0

我创建了一个可运行的 JAR 文件,其中包含一个包含以下代码的类:

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);

} 

在我的其他 Java 应用程序中,我将此 JAR 文件作为外部 JAR 文件导入,并尝试运行这些方法:

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"));
    }
}

加密函数按预期工作,但解密返回 aNullPointerException因为keysetHandle为空。如何获得更新后的值keysetHandle

4

0 回答 0