How can I do the RSA/ECB/PKCS1 Padding mode in Linux? - linux

I am programming with Linux to encrypt a .txt file. I should encrypt a s2 chaine with a given PKI encryption key using RSA in
RSA/ECB/PKCS1Padding mode.
I have excecuted the following commands:
openssl rsautl -encrypt -pkcs -inkey Key.pem -pubin -in s2.txt -out rsa_4096.bin
openssl -encrypt -e -base64 -in rsa_4096.bin -out s2encrypted.txt
There is a problem with the padding mode.

Related

how to achieve openssl smime encrypt with public key functionality in code

I am encrypting a file with this openssl command -
openssl smime -encrypt -aes256 -in <input-file> -binary -outform DEM publicKey.pem
Although the command uses public key but it does not uses RSA as the input file is certainly larger in size.
The same file can be decrypted by -
cat encrypted | openssl smime -decrypt -binary -inform DEM -inkey publickey.pem
My question is, what method openssl uses here to encrypt using public key and how to achieve this command line functionality in code using node.js / ruby ?

Windows version of these openssl commands

Would I have to make any changes to these linux commands to make it work on windows? Do all the pipes and redirects work as they do on linux?
openssl genrsa -out key.pem
openssl rsa -in key.pem -pubout > key.pub
openssl rsa -pubin -modulus -noout < key.pub
#
# to decrypt mess.enc (message encrypted via javascript)
cat mess.enc | openssl base64 -d | openssl rsautl -inkey key.pem -decrypt
I expect I must swap cat for type, and I am hoping the rest will work as it is. Can anyone confirm this?
Equivalent of cat on Windows will be of great help. Rest of the commands are same and should work fine on Windows.
Equivalent of cat on Windows
openssl
cat key.pem
type key.pem
cat=type

openssl set password for private key in command line

I'm trying to encrypt some data via openssl tool, and the question is how can I set password for private.key in this command:
openssl smime -sign -signer /var/www/protected/keys/ym.pem -inkey /var/www/protected/keys/ym.key -nochain -nocerts -outform PEM -nodetach
For those who faces with the same problem:
Remove a passphrase from a private key this way:
openssl rsa -in privateKey.pem -out newPrivateKey.pem

Encrypt and decrypt a string of text with RSA and DES3 key

I am using the Linux command line, I have created a Private Key using the following command:
openssl genrsa -des3 -out private.pem 2048
I have extracted the public key from the private key like so:
openssl rsa -in private.pem -out public.pem -outform PEM -pubout
I want to use the public key to encrypt a string of text, lets say "foo bar", and then decrypt this string again.
How do I go about this?
Thanks
I think you want
openssl rsautl -encrypt -inkey public.pem -pubin -in unencrypted_file.txt -out encrypted_file.ssl
See more at devco.

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

Resources