OpenSSL 密钥加/解密大文件
2018-01-13 本文已影响0人
肆不肆傻
You can generate RSA public and private keys but when it comes to encrypting a large file using this command:
openssl rsautl -encrypt -pubin -inkey public.pem -in LargeFile.zip -out LargeFile_encrypted.zip
It generates the following error:
RSA operation error:
3020:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:.\crypto\rsa\rsa_pk1.c:151:
The Solution is SMIME:
- Generate private and public keys.
openssl req -x509 -nodes -days 100000 -newkey rsa:2048 -keyout privatekey.pem -out publickey.pem
- Encrypt seemingly endless amount of data.
openssl smime -encrypt -aes256 -in LargeFile.zip -binary -outform DEM -out LargeFile_encrypted.zip publickey.pem
- Decrypt
openssl smime -decrypt -in LargeFile_encrypted.zip -binary -inform DEM -inkey privatekey.pem -out LargeFile.zip