简体   繁体   English

如何使用公钥在 Ubuntu 中使用 openssl 加密 XML 文件?

[英]How to encrypt an XML file in Ubuntu with openssl using the public key?

can any one able to tell me how to encrypt and decrypt an xml file using openssl.谁能告诉我如何使用 openssl 加密和解密 xml 文件。 i can able to create privatekey using the linux command openssl genrsa -out private.pem 1024 and got my private key as private.pem also i create public key using openssl rsa -in private.pem -out public.pem -outform PEM -pubout got my public key as public.pem now wat i want is i want to encrypt the xml file using this public key and again want to decrypt using my private key....please help me... thanks in advance我可以使用 linux 命令 openssl genrsa -out private.pem 1024 创建私钥并将我的私钥作为 private.pem 我也可以使用 openssl rsa -in private.pem -out public.pem -outform PEM -pubout 创建公钥现在将我的公钥设为 public.pem 我想要的是我想使用此公钥加密 xml 文件,并再次想使用我的私钥解密...请帮助我...提前致谢

Encrypt with public key:使用公钥加密:

openssl rsautl -encrypt -inkey public.pem -pubin -in xml.file -out encrypted.enc

Decrypt with private key:用私钥解密:

openssl rsautl -decrypt -inkey private.pem -in encrypted.enc -out xml.txt

I think what you are looking for is this:我想你要找的是这个:

  1. If you have a PEM encoded key:如果您有 PEM 编码的密钥:

     openssl pkeyutl -encrypt -in FileToEncrypt -out EncryptedData.enc -inkey ThePathToYourPublicKey -keyform PEM

    If you have a DER encoded key:如果您有 DER 编码的密钥:

     openssl pkeyutl -encrypt -in FileToEncrypt -out EncryptedData.enc -inkey ThePathToYourPublicKey -keyform DER
  2. You then decrypt with:然后你解密:

     openssl pkeyutl -decrypt -in EncryptedData.enc -out DecryptedFile -inkey ThePathToYourPrivateKey

For more information about this you can consult openssl's pkeyutil documentation .有关这方面的更多信息,您可以查阅 openssl 的pkeyutil 文档

If you want to use S/MIME packaging (a standard used to encrypt/decrypt/sign e-mails), see openssl's smime documentation .如果您想使用 S/MIME 打包(用于加密/解密/签署电子邮件的标准),请参阅 openssl 的smime 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM