OpenSSL 无法加载公钥

标签 openssl ssh-keys

尝试在 OSX Yosomite 10.10.2 上通过命令行加密短信

创建了公共(public) .pem key ,如下所示:

ssh-keygen -f ~/.ssh/id_rsa.pub -e -t PKCS8 > id_rsa.pem

如果我尝试加密 myMessage.txt

openssl rsautl -encrypt -inkey ~/.ssh/id_rsa.pem -pubin -in ~/Desktop/myMessage.txt -out ~/Desktop/encrypted.txt

无法加载公钥

如果我输入:

openssl asn1parse -in id_rsa.pem

返回:错误:偏移量太大

但我不知道如何解决它。 我应该更改什么才能使其正常工作?

最佳答案

仍然不知道我的问题出了什么问题,但找到了解决方案:

  1. 生成 RSA key :

    $ openssl genrsa -out key.pem 1024 
    $ openssl rsa -in key.pem -text -noout
    
  2. 将公钥保存在 pub.pem 文件中:

    $ openssl rsa -in key.pem -pubout -out pub.pem 
    $ openssl rsa -in pub.pem -pubin -text -noout 
    
  3. 加密一些数据:

    $ echo test test test > file.txt 
    $ openssl rsautl -encrypt -inkey pub.pem -pubin -in file.txt -out file.bin 
    
  4. 解密加密数据:

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

它就像一个魅力

关于OpenSSL 无法加载公钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29010967/

相关文章:

git - 从 Bitbucket 中删除部署 key

Git 错误 : "Host Key Verification Failed" when connecting to remote repository

ruby - 使用 Ruby OpenSSL 加密文件并使用命令行解密

机器人 : AES encryption/decryption using openSSL

python - 通过 Paramiko 使用字符串中的 key 进行 SSH/SCP

从docker容器内部git克隆项目

git - phpstorm 在错误的目录中寻找 ssh key

c - 将 AuthorityKeyIdentifier 添加到 CertRequest

c++ - 如何在 Windows 7 64 位上安装 OpenSSL

Ruby OpenSSL 与 Linux openssl