grails-app.domain
Class EncryptedData

java.lang.Object
  grails-app.domain.EncryptedData

class EncryptedData

Simple record-based storage for encrypted data. This was created with the intention of storing encrypted passwords, so there are some design decisions that were taken because of that:

  1. It assumes that the data is a string
  2. The space alloted for the encrypted data is limited
  3. The id is assigned, since it's meant to store password lists, which will likely be retrieved by their name

It should be easy enough to modify to handle binary data.

Finally, see this bug report when dealing with domain classes with assigned ids: http://jira.codehaus.org/browse/GRAILS-1984


Field Summary
static def constraints

java.lang.String dataItem

java.lang.String id

static def mapping

private java.lang.String tempData

private java.lang.String tempPassword

static def transients

 
Constructor Summary
EncryptedData()

 
Method Summary
def changePassword(java.lang.String oldPassword, java.lang.String newPassword)

Decrypts the current data item and re-encrypts it with a new password.

java.lang.String decrypt(java.lang.String thePassword)

Decrypts the currently stored data item.

def encrypt(java.lang.String theData, java.lang.String thePassword)

Encrypts a data item and stores it.

def getDecryptedData()

Getter for the decryptedData property.

static EncryptedData getOrCreate(def theId)

Attempts to load a record of EncryptedData with the id, and if it cannot find it then creates and returns an empty one.

void lockDown()

Forget all stored passwords and temporary information

def setDecryptedData(java.lang.String newData)

Sets the value for the decrypted data item and encrypts it.

def setPassword(java.lang.String newPassword)

Password setter.

 
Methods inherited from class java.lang.Object
hashCode, getClass, equals, toString, wait, wait, wait, notify, notifyAll
 

Field Detail

constraints

public static def constraints


dataItem

java.lang.String dataItem


id

java.lang.String id


mapping

public static def mapping


tempData

private java.lang.String tempData


tempPassword

private java.lang.String tempPassword


transients

public static def transients


 
Constructor Detail

EncryptedData

EncryptedData()


 
Method Detail

changePassword

public def changePassword(java.lang.String oldPassword, java.lang.String newPassword)
Decrypts the current data item and re-encrypts it with a new password. Will raise assertion errors if the dataItem has not been set or if there is a password error.


decrypt

public java.lang.String decrypt(java.lang.String thePassword)
Decrypts the currently stored data item. Will raise an assertion error if there isn't an encrypted data item or the password is wrong.


encrypt

public def encrypt(java.lang.String theData, java.lang.String thePassword)
Encrypts a data item and stores it.


getDecryptedData

public def getDecryptedData()
Getter for the decryptedData property. Will attempt to decrypt it with the cached password.


getOrCreate

public static EncryptedData getOrCreate(def theId)
Attempts to load a record of EncryptedData with the id, and if it cannot find it then creates and returns an empty one.


lockDown

public void lockDown()
Forget all stored passwords and temporary information


setDecryptedData

public def setDecryptedData(java.lang.String newData)
Sets the value for the decrypted data item and encrypts it. It requires that a password was previously set and cached, otherwise call "encrypt" directly.


setPassword

public def setPassword(java.lang.String newPassword)
Password setter. If there is a currently existing data item, it requires the previous password to be cached so that it can re- encrypt the data.


 

Groovy Documentation