Created
December 31, 2021 07:59
-
-
Save ambakshi/b2501d6a765774221afdeaa0706a0d18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# | |
# Create a variable `$key` for use in powershell as a AES encyrption key | |
# constant with (ConvertFrom-SecureString)[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/convertfrom-securestring?view=powershell-7.2)] | |
# | |
# param: $1 secret key (optional, default: secret) | |
# param: $2 cipher (optional, default: aes-256-cbc) | |
# output: An byte array (in decimals), the size of the encryption key (AES256 = 32 bytes) | |
genkey() { | |
openssl enc -"${2:-aes-256-cbc}" -k "${1:-secret}" -iter +100 -P -md sha1 | \ | |
awk -F'=' '/key/{print $2}' | \ | |
sed -re 's/(.)(.)/\1\2\n/g' | \ | |
while read -r HEX 2>/dev/null; do | |
test -z "$HEX" || echo $(( 16#$HEX )) | |
done | |
return 0 | |
} | |
if key=("$(genkey "$@")"); then | |
echo "${key[@]}" | tr '\n' ',' | sed -r 's/^(.*),$/\$key = @\(\1\)/' | |
echo | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment