yamunakutty
yamunakutty

Reputation: 1

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. 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

Answers (2)

Zimba
Zimba

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

sinharaj
sinharaj

Reputation: 1093

I think what you are looking for is this:

  1. 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
    
  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.

If you want to use S/MIME packaging (a standard used to encrypt/decrypt/sign e-mails), see openssl's smime documentation.

Upvotes: 0

Related Questions