-
1. Re: how to encrypt and decrypt
cosmo Jun 9, 2010 8:50 PM (in response to vasukihn)If you are using JPA you could take advantage of the @PostLoad and @PrePersist callback methods to achieve what you want.
-
2. Re: how to encrypt and decrypt
vasukihn Jun 14, 2010 12:46 PM (in response to vasukihn)Hi Aldo,
I tried using that in my action class ie.,DeviceHome.java but no luck..
I just annotated postload to my pastload method in DeviceHome class. When i try to display the records in the view page that method doesn't get executed.
Could you explain how to use it?
-
3. Re: how to encrypt and decrypt
cosmo Jun 14, 2010 7:34 PM (in response to vasukihn)The methods have to be within the entity bean.
-
4. Re: how to encrypt and decrypt
kapitanpetko Jun 14, 2010 10:21 PM (in response to vasukihn)
Aldo Bonzi wrote on Jun 14, 2010 19:34:
The methods have to be within the entity bean.And how will the entity bean get a hold of the key? As I said in another (suspiciously similar...) thread, DES encryption is a bad idea, especially when you obviously don't know what you are doing. The data encrypted may not be particularly valuable, so this may be just for show (See we have encryption! Our app is secure!), but still. Cf Security theater
That said, this has to be done in the Home class by calling the component that knows how to encrypt/decrypt after the entity is loaded from DB and before it is displayed.
-
5. Re: how to encrypt and decrypt
gurkavcu Jun 15, 2010 2:36 PM (in response to vasukihn)You can use Transient functions in entities.You can define a @Transient variable like encryptedPassword and use it to modify your entity field like :
// Entity field private String password; @Transient public void setEncryptedPassword(String password) { setPassword( new BasicPasswordEncryptor().encryptPassword(password)); } @Transient public String getEncryptedPassword() { return ""; }
in your Device.xhtml
<h:inputText value="#{entity.encryptedPassword}" />
I am using JASPYT api to encrypt user's passwords like this way.
http://www.jasypt.org/ -
6. Re: how to encrypt and decrypt
gurkavcu Jun 15, 2010 2:45 PM (in response to vasukihn)
Umut Fikret Gürkavcu wrote on Jun 15, 2010 14:36:
You can use Transient functions in entities.You can define a @Transient variable like encryptedPassword and use it to modify your entity field like :
// Entity field private String password; @Transient public void setEncryptedPassword(String password) { setPassword( new BasicPasswordEncryptor().encryptPassword(password)); } @Transient public String getEncryptedPassword() { return ""; }
in your Device.xhtml<h:inputSecret id="passwordText" value="#{entityHome.instance.encryptedPassword}" required="true" label="password" size="35"> <f:validateLength minimum="8"/> </h:inputSecret>
I am using JASPYT api to encrypt user's passwords like this way.
http://www.jasypt.org/Click HELP for text formatting instructions. Then edit this text and check the preview.
-
7. Re: how to encrypt and decrypt
cosmo Jun 16, 2010 9:56 PM (in response to vasukihn)
Nikolay Elenkov wrote on Jun 14, 2010 22:21:
Aldo Bonzi wrote on Jun 14, 2010 19:34:
The methods have to be within the entity bean.
And how will the entity bean get a hold of the key?That's certainly right. I was so focused on trying to propose a transparent solution to rest of the application that i didn't see the obvius.