I've created a runnable JAR file which has a class with this code:
static KeysetHandle keysetHandle = null;
public String encrypt(String plainText){
Config.register(AeadConfig.TINK_1_1_0);
// GENERATE key
// key generated using tink library
keysetHandle = KeysetHandle.generateNew(AeadKeyTemplates.AES256_GCM);
}
public String decrypt(String cipherText){
//using the key generated during encryption to decrypt
Aead aeadDecryption = AeadFactory.getPrimitive(keysetHandle);
}
In my other Java application I've imported this JAR file as an external JAR file and am trying to run these methods:
import core.Crypto;
public class Sample {
public static void main(String[] args) {
// TODO Auto-generated method stub
Crypto crypto = new Crypto();
System.out.println(crypto.encrypt("sampleText"));
System.out.println(crypto.decrypt("XXX"));
}
}
The encrypt function works as expected, but the decrypt returns a NullPointerException
because keysetHandle
is null. How do I get the updated value for keysetHandle
?