piotom
piotom

Reputation: 91

Jasypt and asymmetric encryption

I want to use the Jasypt library to decrypt properties in Spring through the EncryptablePropertyPlaceholderConfigurer class. I want to encrypt/decrypt these properties using the asymmetric public/private key approach.

Could you please confirm the Jasypt does or does not support it (out of the box or maybe using the JCE)? If not is there any other library doing it (providing both the spring integration and asymmetric public/private key approach)?

Upvotes: 2

Views: 4299

Answers (3)

It supports Asymmetric encryption. You can generate private and public key with these commands

openssl genpkey -out zisky.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2048<br>
openssl rsa -in zisky.pem -pubout > zisky.pub

Add these properties:

jasypt.encryptor.privateKeyFormat=PEM<br>
jasypt.encryptor.privateKeyLocation=classpath:my_example.pem

Use version 3.0.3.

Upvotes: 1

piotom
piotom

Reputation: 91

Finally, I used the following solution. Maybe somebody will find it is useful.

  1. Wrote a simple helper class decrypting the data using RSA (you can find how to do it here)
  2. Implemented my own version of PropertyPlaceholderConfigurer class by extending the original one (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) and calling the helper class to decode the data, whenever an encrypted property value was found.

Upvotes: 3

m0skit0
m0skit0

Reputation: 25874

I don't know about Jasypt but asymmetric encryption is not suitable to encrypt data bigger than its key size. It's unlikely that any library offers a full encryption using an asymmetric algorithm. That's not the purpose of asymmetric encryption.

Usually you share a symmetric key (e.g. AES) using an asymmetric encryption (e.g. RSA).

Upvotes: 0

Related Questions