我有一个使用AES256
和密钥salam
加密的私钥。
我想解密它并读取其中的私钥。
我写下代码:
public CertReader(String password, Context context) {
mContext = context;
pf = new Password(password.toCharArray());
InputStream Certin = mContext.getResources().openRawResource(
R.raw.kxx_2048_sign);
PEMReader pemRd = openPEMResource(Certin, pf);
Object o = null;
try {
o = pemRd.readObject();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
X509Certificate x509 = ((X509Certificate) o);
logging.l(x509.toString());
Certin = mContext.getResources().openRawResource(
R.raw.kxx_2048);
pemRd = openPEMResource(Certin, pf);
try {
o = pemRd.readObject(); //My Program exit with error here.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// KeyPair key = ((KeyPair)o);
// logging.l(key.toString());
}
private PEMReader openPEMResource(InputStream Certin, PasswordFinder pGet) {
Reader fRd = new BufferedReader(new InputStreamReader(Certin));
return new PEMReader(fRd, pGet);
}
private static class Password implements PasswordFinder {
char[] password;
Password(char[] word) {
this.password = word;
}
public char[] getPassword() {
return password;
}
}
kxx_2048_sign.crt
是一个证书,它没有问题,因为它没有加密。
但kxx_2048.key
已使用AES256
进行加密,而在o = pemRd.readObject();
我收到了以下错误:
java.lang.IllegalAccessError: tried to access class org.bouncycastle.openssl.PEMUtilities from class org.bouncycastle.openssl.PEMReader$KeyPairParser
重点开始:
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,5C76FCD87.....
有什么问题?
我在PC上检查了它并且它工作正确但在Android中它不起作用。