class SignSealUtilitySignSealUtility<E,V> implements Serializable {
final static long serialVersionUID = 2648720192864531932L;
private HashMapHashMap<E,V> ssnMap;
private SealedObject sealedSsnMap;
private SignedObject signedSsnMap;
public SignSealUtility() {
ssnMap = new HashMapHashMap<E,V>();
}
public void seal(Cipher cipher) throws Exception {
sealedSsnMap = new SealedObject(ssnMap, cipher);
// Now set the Map to null so that original data does not remain in cleartext
ssnMap = null;
}
public void unseal(Cipher cipher) throws Exception {
ssnMap = (HashMapHashMap<E,V>)sealedSsnMap.getObject(cipher);
}
public void sign(Signature sig, PrivateKey key) throws Exception {
signedSsnMap = new SignedObject(ssnMap, key, sig);
ssnMap = null;
}
public void unsign(Signature sig, PublicKey key) throws Exception {
if(signedSsnMap.verify(key, sig)) {
ssnMap = (HashMapHashMap<E,V>)signedSsnMap.getObject();
}
}
public Object getdata(Object key) throws Exception {
return ssnMap.get(key);
}
public void setData(ObjectE key, ObjectV data) throws Exception {
ssnMap.put(key, data);
}
}
|