-
-
Save luk0y/843b0651525164dc5d58cf0abf88b719 to your computer and use it in GitHub Desktop.
Create a public RSA key from modulus and exponent on the command line
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
#!/bin/bash | |
set -e | |
b2hex() { echo -n $1|base64 --decode | xxd -p -u | tr -d \\n; } | |
modulus=$(b2hex u2/nlDLMbqLY+XBnWlqHv74a/wvmPoefKv+5NkTU0sbQAEMN7Gar9Hgp50uMUQhiOhwO6L4hezrY021etPyh2Q==) | |
exponent=$(b2hex AQAB) | |
asn1conf=$(echo -e "asn1=SEQUENCE:pubkeyinfo\n[pubkeyinfo]\nalgorithm=SEQUENCE:rsa_alg\npubkey=BITWRAP,SEQUENCE:rsapubkey\n[rsa_alg]\nalgorithm=OID:rsaEncryption\nparameter=NULL\n[rsapubkey]\nn=INTEGER:0x$modulus\ne=INTEGER:0x$exponent" | openssl asn1parse -genconf /dev/stdin -noout -out /dev/stdout | base64) | |
echo "Secret message wohoo!" | openssl rsautl -encrypt -keyform der -pubin -inkey <(base64 --decode <<<$asn1conf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment