OpenSSL unable to load Public Key

后端 未结 4 1541
忘了有多久
忘了有多久 2021-02-04 11:36

Trying to encrypt a text message via command line on OSX Yosomite 10.10.2

Created public .pem key like this:

ssh-keygen -f ~/.ssh/id_rsa.pub         


        
4条回答
  •  隐瞒了意图╮
    2021-02-04 12:29

    Still don't know what went wrong in my question but found a solution:

    1) Generate RSA key:

    $ openssl genrsa -out key.pem 1024 
    $ openssl rsa -in key.pem -text -noout 
    

    2) Save public key in pub.pem file:

    $ openssl rsa -in key.pem -pubout -out pub.pem 
    $ openssl rsa -in pub.pem -pubin -text -noout 
    

    3) Encrypt some data:

    $ echo test test test > file.txt 
    $ openssl rsautl -encrypt -inkey pub.pem -pubin -in file.txt -out file.bin 
    

    4) Decrypt encrypted data:

    $ openssl rsautl -decrypt -inkey key.pem -in file.bin 
    

    It works like a charm

    Thanks to Marek Marcola for providing the information http://openssl.6102.n7.nabble.com/Re-Can-I-use-my-own-keys-with-openssl-for-RSA-enc-dec-td12506.html

提交回复
热议问题