-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
498 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/rickar/props" | ||
) | ||
|
||
var ( | ||
decryptFlags = flag.NewFlagSet("decrypt", flag.ExitOnError) | ||
decryptValue = decryptFlags.String("value", "", "`encrypted` value to decrypt (including algorithm prefix)") | ||
decryptPass = decryptFlags.String("password", "", "`password` to decrypt the value") | ||
) | ||
|
||
func init() { | ||
decryptFlags.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "decrypt: decrypt an encrypted property value\n") | ||
decryptFlags.PrintDefaults() | ||
} | ||
} | ||
|
||
func decrypt() { | ||
if *decryptValue == "" { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the value parameter is required\n") | ||
decryptFlags.Usage() | ||
os.Exit(100) | ||
} | ||
if *decryptPass == "" { | ||
*decryptPass = readPassword("Password:", decryptFlags, 100) | ||
} | ||
|
||
dec, err := props.Decrypt(*decryptPass, *decryptValue) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "decrypt error: %v\n", err) | ||
os.Exit(101) | ||
} | ||
fmt.Println(dec) | ||
} | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/rickar/props" | ||
) | ||
|
||
var ( | ||
decryptFlags = flag.NewFlagSet("decrypt", flag.ExitOnError) | ||
decryptValue = decryptFlags.String("value", "", "`encrypted` value to decrypt (including algorithm prefix)") | ||
decryptPass = decryptFlags.String("password", "", "`password` to decrypt the value") | ||
) | ||
|
||
func init() { | ||
decryptFlags.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "decrypt: decrypt an encrypted property value\n") | ||
decryptFlags.PrintDefaults() | ||
} | ||
} | ||
|
||
func decrypt() { | ||
if *decryptValue == "" { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the value parameter is required\n") | ||
decryptFlags.Usage() | ||
os.Exit(100) | ||
} | ||
if *decryptPass == "" { | ||
*decryptPass = readPassword("Password:", decryptFlags, 100) | ||
} | ||
|
||
dec, err := props.Decrypt(*decryptPass, *decryptValue) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "decrypt error: %v\n", err) | ||
os.Exit(101) | ||
} | ||
fmt.Println(dec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,86 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/rickar/props" | ||
) | ||
|
||
var ( | ||
decryptFileFlags = flag.NewFlagSet("decryptFile", flag.ExitOnError) | ||
decryptFilePath = decryptFileFlags.String("path", "", "properties `file` to decrypt") | ||
decryptFilePass = decryptFileFlags.String("password", "", "`password` to decrypt the values") | ||
decryptFileOutput = decryptFileFlags.String("output", "", "output `file` to write results (default is input file)") | ||
) | ||
|
||
func init() { | ||
decryptFileFlags.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "decryptFile: decrypt encrypted values in a property file\n") | ||
decryptFileFlags.PrintDefaults() | ||
} | ||
} | ||
|
||
func decryptFile() { | ||
if *decryptFilePath == "" { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the path parameter is required\n") | ||
decryptFileFlags.Usage() | ||
os.Exit(200) | ||
} else { | ||
stat, err := os.Stat(*decryptFilePath) | ||
if err != nil || stat.IsDir() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the path parameter must be an existing, readable file\n") | ||
decryptFileFlags.Usage() | ||
os.Exit(201) | ||
} | ||
} | ||
if *decryptFilePass == "" { | ||
*decryptFilePass = readPassword("Password:", decryptFileFlags, 202) | ||
} | ||
if *decryptFileOutput == "" { | ||
*decryptFileOutput = *decryptFilePath | ||
} | ||
|
||
f, err := os.Open(*decryptFilePath) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "unable to read property file: %v\n", err) | ||
os.Exit(203) | ||
} | ||
defer f.Close() | ||
|
||
found := 0 | ||
var result bytes.Buffer | ||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if strings.Contains(line, props.EncryptAESGCM) { | ||
found++ | ||
i := strings.Index(line, props.EncryptAESGCM) | ||
val := line[i:] | ||
line := line[:i] | ||
enc, err := props.Decrypt(*decryptFilePass, val) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "unable to decrypt property: %v\n", err) | ||
os.Exit(204) | ||
} | ||
result.WriteString(line) | ||
result.WriteString(props.EncryptNone) | ||
result.WriteString(enc) | ||
result.WriteRune('\n') | ||
} else { | ||
result.WriteString(line) | ||
result.WriteRune('\n') | ||
} | ||
} | ||
f.Close() | ||
err = os.WriteFile(*decryptFileOutput, result.Bytes(), 0o644) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "unable to write output: %v\n", err) | ||
os.Exit(205) | ||
} | ||
fmt.Printf("%d properties decrypted\n", found) | ||
} | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/rickar/props" | ||
) | ||
|
||
var ( | ||
decryptFileFlags = flag.NewFlagSet("decryptFile", flag.ExitOnError) | ||
decryptFilePath = decryptFileFlags.String("path", "", "properties `file` to decrypt") | ||
decryptFilePass = decryptFileFlags.String("password", "", "`password` to decrypt the values") | ||
decryptFileOutput = decryptFileFlags.String("output", "", "output `file` to write results (default is input file)") | ||
) | ||
|
||
func init() { | ||
decryptFileFlags.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "decryptFile: decrypt encrypted values in a property file\n") | ||
decryptFileFlags.PrintDefaults() | ||
} | ||
} | ||
|
||
func decryptFile() { | ||
if *decryptFilePath == "" { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the path parameter is required\n") | ||
decryptFileFlags.Usage() | ||
os.Exit(200) | ||
} else { | ||
stat, err := os.Stat(*decryptFilePath) | ||
if err != nil || stat.IsDir() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the path parameter must be an existing, readable file\n") | ||
decryptFileFlags.Usage() | ||
os.Exit(201) | ||
} | ||
} | ||
if *decryptFilePass == "" { | ||
*decryptFilePass = readPassword("Password:", decryptFileFlags, 202) | ||
} | ||
if *decryptFileOutput == "" { | ||
*decryptFileOutput = *decryptFilePath | ||
} | ||
|
||
f, err := os.Open(*decryptFilePath) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "unable to read property file: %v\n", err) | ||
os.Exit(203) | ||
} | ||
defer f.Close() | ||
|
||
found := 0 | ||
var result bytes.Buffer | ||
scanner := bufio.NewScanner(f) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if strings.Contains(line, props.EncryptAESGCM) { | ||
found++ | ||
i := strings.Index(line, props.EncryptAESGCM) | ||
val := line[i:] | ||
line := line[:i] | ||
enc, err := props.Decrypt(*decryptFilePass, val) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "unable to decrypt property: %v\n", err) | ||
os.Exit(204) | ||
} | ||
result.WriteString(line) | ||
result.WriteString(props.EncryptNone) | ||
result.WriteString(enc) | ||
result.WriteRune('\n') | ||
} else { | ||
result.WriteString(line) | ||
result.WriteRune('\n') | ||
} | ||
} | ||
f.Close() | ||
err = os.WriteFile(*decryptFileOutput, result.Bytes(), 0o644) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "unable to write output: %v\n", err) | ||
os.Exit(205) | ||
} | ||
fmt.Printf("%d properties decrypted\n", found) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/rickar/props" | ||
) | ||
|
||
var ( | ||
encryptFlags = flag.NewFlagSet("encrypt", flag.ExitOnError) | ||
encryptValue = encryptFlags.String("value", "", "`plaintext` value to encrypt") | ||
encryptPass = encryptFlags.String("password", "", "`password` to encrypt the value") | ||
encryptAlg = encryptFlags.String("alg", props.EncryptDefault, "encryption `algorithm` to use (see props.Encrypt*)") | ||
) | ||
|
||
func init() { | ||
encryptFlags.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "encrypt: encrypt a value for use in a property file\n") | ||
encryptFlags.PrintDefaults() | ||
} | ||
} | ||
|
||
func encrypt() { | ||
if *encryptValue == "" { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the value parameter is required\n") | ||
encryptFlags.Usage() | ||
os.Exit(300) | ||
} | ||
if *encryptPass == "" { | ||
*encryptPass = readPassword("Password:", encryptFlags, 301) | ||
} | ||
if *encryptAlg != props.EncryptAESGCM { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the alg parameter must be an encryption algorithm id from props\n") | ||
encryptFlags.Usage() | ||
os.Exit(302) | ||
} | ||
|
||
switch len(*encryptPass) { | ||
case 16, 24, 32: | ||
default: | ||
fmt.Fprintf(flag.CommandLine.Output(), "the password parameter must be 16, 24, or 32 bytes\n") | ||
encryptFlags.Usage() | ||
os.Exit(303) | ||
} | ||
|
||
enc, err := props.Encrypt(*encryptAlg, *encryptPass, *encryptValue) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "encrypt error: %v\n", err) | ||
os.Exit(304) | ||
} | ||
fmt.Println(enc) | ||
} | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/rickar/props" | ||
) | ||
|
||
var ( | ||
encryptFlags = flag.NewFlagSet("encrypt", flag.ExitOnError) | ||
encryptValue = encryptFlags.String("value", "", "`plaintext` value to encrypt") | ||
encryptPass = encryptFlags.String("password", "", "`password` to encrypt the value") | ||
encryptAlg = encryptFlags.String("alg", props.EncryptDefault, "encryption `algorithm` to use (see props.Encrypt*)") | ||
) | ||
|
||
func init() { | ||
encryptFlags.Usage = func() { | ||
fmt.Fprintf(flag.CommandLine.Output(), "encrypt: encrypt a value for use in a property file\n") | ||
encryptFlags.PrintDefaults() | ||
} | ||
} | ||
|
||
func encrypt() { | ||
if *encryptValue == "" { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the value parameter is required\n") | ||
encryptFlags.Usage() | ||
os.Exit(300) | ||
} | ||
if *encryptPass == "" { | ||
*encryptPass = readPassword("Password:", encryptFlags, 301) | ||
} | ||
if *encryptAlg != props.EncryptAESGCM { | ||
fmt.Fprintf(flag.CommandLine.Output(), "the alg parameter must be an encryption algorithm id from props\n") | ||
encryptFlags.Usage() | ||
os.Exit(302) | ||
} | ||
|
||
switch len(*encryptPass) { | ||
case 16, 24, 32: | ||
default: | ||
fmt.Fprintf(flag.CommandLine.Output(), "the password parameter must be 16, 24, or 32 bytes\n") | ||
encryptFlags.Usage() | ||
os.Exit(303) | ||
} | ||
|
||
enc, err := props.Encrypt(*encryptAlg, *encryptPass, *encryptValue) | ||
if err != nil { | ||
fmt.Fprintf(flag.CommandLine.Output(), "encrypt error: %v\n", err) | ||
os.Exit(304) | ||
} | ||
fmt.Println(enc) | ||
} |
Oops, something went wrong.