Reputation: 1
can any one able to tell me how to encrypt and decrypt an xml file using openssl. 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
Upvotes: 0
Views: 1989
Reputation: 3643
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
Upvotes: 0
Reputation: 1093
I think what you are looking for is this:
If you have a PEM encoded key:
openssl pkeyutl -encrypt -in FileToEncrypt -out EncryptedData.enc -inkey ThePathToYourPublicKey -keyform PEM
If you have a DER encoded key:
openssl pkeyutl -encrypt -in FileToEncrypt -out EncryptedData.enc -inkey ThePathToYourPublicKey -keyform DER
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.
If you want to use S/MIME packaging (a standard used to encrypt/decrypt/sign e-mails), see openssl's smime documentation.
Upvotes: 0