5
关键密钥库
我使用密钥库来保护我的私人密钥,但线的时候:存储在Android中使用
FileOutputStream fos = ctx.openFileOutput("bs.keystore", Context.MODE_PRIVATE);
执行我有这样的例外:
'java.lang.NullPointerException'.
我不明白的地方是问题。
代码:
private Context ctx;
public DataSec(Context ctx)
{
ctx = this.ctx;
}
public void genKey() throws Exception
{
SecretKey key = KeyGenerator.getInstance("AES").generateKey();
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, "clavedekey".toCharArray());
PasswordProtection pass = new PasswordProtection("fedsgjk".toCharArray());
KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(key);
ks.setEntry("secretKeyAlias", skEntry, pass);
FileOutputStream fos = ctx.openFileOutput("bs.keystore", Context.MODE_PRIVATE);
ks.store(fos, "clavedekey".toCharArray());
fos.close();
}
感谢您的帮助!
我在这个问题上失去了一个多小时。我真的觉得很傻。谢谢! – gzanitti 2013-02-20 16:01:57
这就是为什么你应该在方法参数上使用final关键字。 – 2014-03-31 14:17:33
hello Raghav我们如何才能知道我们的钥匙是否已被保存,这意味着有什么方法可以从钥匙库中取回钥匙。 – 2014-06-13 12:09:58