Create veracrypt volumes using golang
Trying to pass go command line instructions to start veracrypt but it gets exit status 1 or doesn't show an error and doesn't create the requested volume.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Run()
// io.WriteString(stdin, "1234")
// io.WriteString(stdin, "y")
// io.WriteString(stdin, "1234")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
fmt.Println("Result: " + out.String())
// outin, err := cmd.CombinedOutput()
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("%sn", outin)
}
The commented part is the other approach that I used which results in exit status 1.
The reason for passing the 3 strings at the end "1234", y, "1234" is because we want to enter the password interactively.
The code doesn't end up creating the veracrypt files.
here is the commandline instructions for veracrypt that we are trying to invoke using golang.
veracrypt -c ~/test/samplevolume.vcrypt --volume-type normal --filesystem FAT --hash SHA256 --encryption AES --size 10M --pim 1234 -k= --random-source ~/test/README.md
Note: Everything is on linux if that matters.
Edit: Also, I am new to golang, sorry if I have made an obvious mistake.
go command-line veracrypt
add a comment |
Trying to pass go command line instructions to start veracrypt but it gets exit status 1 or doesn't show an error and doesn't create the requested volume.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Run()
// io.WriteString(stdin, "1234")
// io.WriteString(stdin, "y")
// io.WriteString(stdin, "1234")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
fmt.Println("Result: " + out.String())
// outin, err := cmd.CombinedOutput()
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("%sn", outin)
}
The commented part is the other approach that I used which results in exit status 1.
The reason for passing the 3 strings at the end "1234", y, "1234" is because we want to enter the password interactively.
The code doesn't end up creating the veracrypt files.
here is the commandline instructions for veracrypt that we are trying to invoke using golang.
veracrypt -c ~/test/samplevolume.vcrypt --volume-type normal --filesystem FAT --hash SHA256 --encryption AES --size 10M --pim 1234 -k= --random-source ~/test/README.md
Note: Everything is on linux if that matters.
Edit: Also, I am new to golang, sorry if I have made an obvious mistake.
go command-line veracrypt
add a comment |
Trying to pass go command line instructions to start veracrypt but it gets exit status 1 or doesn't show an error and doesn't create the requested volume.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Run()
// io.WriteString(stdin, "1234")
// io.WriteString(stdin, "y")
// io.WriteString(stdin, "1234")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
fmt.Println("Result: " + out.String())
// outin, err := cmd.CombinedOutput()
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("%sn", outin)
}
The commented part is the other approach that I used which results in exit status 1.
The reason for passing the 3 strings at the end "1234", y, "1234" is because we want to enter the password interactively.
The code doesn't end up creating the veracrypt files.
here is the commandline instructions for veracrypt that we are trying to invoke using golang.
veracrypt -c ~/test/samplevolume.vcrypt --volume-type normal --filesystem FAT --hash SHA256 --encryption AES --size 10M --pim 1234 -k= --random-source ~/test/README.md
Note: Everything is on linux if that matters.
Edit: Also, I am new to golang, sorry if I have made an obvious mistake.
go command-line veracrypt
Trying to pass go command line instructions to start veracrypt but it gets exit status 1 or doesn't show an error and doesn't create the requested volume.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Run()
// io.WriteString(stdin, "1234")
// io.WriteString(stdin, "y")
// io.WriteString(stdin, "1234")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
fmt.Println("Result: " + out.String())
// outin, err := cmd.CombinedOutput()
// if err != nil {
// log.Fatal(err)
// }
// fmt.Printf("%sn", outin)
}
The commented part is the other approach that I used which results in exit status 1.
The reason for passing the 3 strings at the end "1234", y, "1234" is because we want to enter the password interactively.
The code doesn't end up creating the veracrypt files.
here is the commandline instructions for veracrypt that we are trying to invoke using golang.
veracrypt -c ~/test/samplevolume.vcrypt --volume-type normal --filesystem FAT --hash SHA256 --encryption AES --size 10M --pim 1234 -k= --random-source ~/test/README.md
Note: Everything is on linux if that matters.
Edit: Also, I am new to golang, sorry if I have made an obvious mistake.
go command-line veracrypt
go command-line veracrypt
edited Jan 3 at 18:28
user-2147482539
asked Jan 3 at 15:42
user-2147482539user-2147482539
12
12
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You have used the tilde symbol ~ in your path names, but this is not a valid character at the beginning of a Unix path.
Rather, some shells substitute the tilde with the path of the user's home directory before passing it on to the operating system.
Because you are not using a shell, you must provide the actual directory yourself. You cannot use the tilde in the beginning of the paths.
Thank you, I fixed that but it's still not producing a result. No errors, it just prints nothing for out.String() . editing the main code to showcase how i changed it.
– user-2147482539
Jan 3 at 18:17
Hmm. You should do some error checking then. There is at least one place in your code where you are ignoring errors.
– Michael Hampton
Jan 3 at 18:20
Thank you for that! Still nothing yet.
– user-2147482539
Jan 3 at 18:29
add a comment |
So I figured out what I was doing wrong.
I should have been using the cmd.Start and cmd.Wait. so here is the corrected version. This version can also take user input correctly.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Start()
io.WriteString(stdin, "1234n")
io.WriteString(stdin, "yn")
io.WriteString(stdin, "1234n")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v", err)
}
fmt.Println("Result: " + out.String())
}
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025483%2fcreate-veracrypt-volumes-using-golang%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have used the tilde symbol ~ in your path names, but this is not a valid character at the beginning of a Unix path.
Rather, some shells substitute the tilde with the path of the user's home directory before passing it on to the operating system.
Because you are not using a shell, you must provide the actual directory yourself. You cannot use the tilde in the beginning of the paths.
Thank you, I fixed that but it's still not producing a result. No errors, it just prints nothing for out.String() . editing the main code to showcase how i changed it.
– user-2147482539
Jan 3 at 18:17
Hmm. You should do some error checking then. There is at least one place in your code where you are ignoring errors.
– Michael Hampton
Jan 3 at 18:20
Thank you for that! Still nothing yet.
– user-2147482539
Jan 3 at 18:29
add a comment |
You have used the tilde symbol ~ in your path names, but this is not a valid character at the beginning of a Unix path.
Rather, some shells substitute the tilde with the path of the user's home directory before passing it on to the operating system.
Because you are not using a shell, you must provide the actual directory yourself. You cannot use the tilde in the beginning of the paths.
Thank you, I fixed that but it's still not producing a result. No errors, it just prints nothing for out.String() . editing the main code to showcase how i changed it.
– user-2147482539
Jan 3 at 18:17
Hmm. You should do some error checking then. There is at least one place in your code where you are ignoring errors.
– Michael Hampton
Jan 3 at 18:20
Thank you for that! Still nothing yet.
– user-2147482539
Jan 3 at 18:29
add a comment |
You have used the tilde symbol ~ in your path names, but this is not a valid character at the beginning of a Unix path.
Rather, some shells substitute the tilde with the path of the user's home directory before passing it on to the operating system.
Because you are not using a shell, you must provide the actual directory yourself. You cannot use the tilde in the beginning of the paths.
You have used the tilde symbol ~ in your path names, but this is not a valid character at the beginning of a Unix path.
Rather, some shells substitute the tilde with the path of the user's home directory before passing it on to the operating system.
Because you are not using a shell, you must provide the actual directory yourself. You cannot use the tilde in the beginning of the paths.
answered Jan 3 at 16:46
Michael HamptonMichael Hampton
7,44133470
7,44133470
Thank you, I fixed that but it's still not producing a result. No errors, it just prints nothing for out.String() . editing the main code to showcase how i changed it.
– user-2147482539
Jan 3 at 18:17
Hmm. You should do some error checking then. There is at least one place in your code where you are ignoring errors.
– Michael Hampton
Jan 3 at 18:20
Thank you for that! Still nothing yet.
– user-2147482539
Jan 3 at 18:29
add a comment |
Thank you, I fixed that but it's still not producing a result. No errors, it just prints nothing for out.String() . editing the main code to showcase how i changed it.
– user-2147482539
Jan 3 at 18:17
Hmm. You should do some error checking then. There is at least one place in your code where you are ignoring errors.
– Michael Hampton
Jan 3 at 18:20
Thank you for that! Still nothing yet.
– user-2147482539
Jan 3 at 18:29
Thank you, I fixed that but it's still not producing a result. No errors, it just prints nothing for out.String() . editing the main code to showcase how i changed it.
– user-2147482539
Jan 3 at 18:17
Thank you, I fixed that but it's still not producing a result. No errors, it just prints nothing for out.String() . editing the main code to showcase how i changed it.
– user-2147482539
Jan 3 at 18:17
Hmm. You should do some error checking then. There is at least one place in your code where you are ignoring errors.
– Michael Hampton
Jan 3 at 18:20
Hmm. You should do some error checking then. There is at least one place in your code where you are ignoring errors.
– Michael Hampton
Jan 3 at 18:20
Thank you for that! Still nothing yet.
– user-2147482539
Jan 3 at 18:29
Thank you for that! Still nothing yet.
– user-2147482539
Jan 3 at 18:29
add a comment |
So I figured out what I was doing wrong.
I should have been using the cmd.Start and cmd.Wait. so here is the corrected version. This version can also take user input correctly.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Start()
io.WriteString(stdin, "1234n")
io.WriteString(stdin, "yn")
io.WriteString(stdin, "1234n")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v", err)
}
fmt.Println("Result: " + out.String())
}
add a comment |
So I figured out what I was doing wrong.
I should have been using the cmd.Start and cmd.Wait. so here is the corrected version. This version can also take user input correctly.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Start()
io.WriteString(stdin, "1234n")
io.WriteString(stdin, "yn")
io.WriteString(stdin, "1234n")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v", err)
}
fmt.Println("Result: " + out.String())
}
add a comment |
So I figured out what I was doing wrong.
I should have been using the cmd.Start and cmd.Wait. so here is the corrected version. This version can also take user input correctly.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Start()
io.WriteString(stdin, "1234n")
io.WriteString(stdin, "yn")
io.WriteString(stdin, "1234n")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v", err)
}
fmt.Println("Result: " + out.String())
}
So I figured out what I was doing wrong.
I should have been using the cmd.Start and cmd.Wait. so here is the corrected version. This version can also take user input correctly.
func main() {
cmd := exec.Command("veracrypt",
"-c", "/home/user/test/samplevolume.vcrypt",
"--volume-type", "normal",
"--filesystem", "FAT",
"--hash", "SHA256",
"--encryption", "AES",
"--size", "10M",
"--pim", "1234",
"-k", "",
"--random-source", "/home/user/test/README.md")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr
stdin, err := cmd.StdinPipe()
if err != nil {
fmt.Println(fmt.Sprint(err))
}
go func() {
defer stdin.Close()
err = cmd.Start()
io.WriteString(stdin, "1234n")
io.WriteString(stdin, "yn")
io.WriteString(stdin, "1234n")
}()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
err = cmd.Wait()
if err != nil {
fmt.Printf("Command finished with error: %v", err)
}
fmt.Println("Result: " + out.String())
}
answered Jan 4 at 14:44
user-2147482539user-2147482539
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54025483%2fcreate-veracrypt-volumes-using-golang%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
