java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0c0000b9:ASN.1 encodin

支付宝踩坑:java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0c0000b9:ASN.1 encoding routines:OPENSSL_internal:WRONG_TAG

这个问题是:Android4.1的问题,4.1之后就是加KeyFactory keyf = KeyFactory.getInstance(ALGORITHM, "BC");

PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKey));
KeyFactory keyf = KeyFactory.getInstance(ALGORITHM, "BC");//
PrivateKey priKey = keyf.generatePrivate(priPKCS8);

java.security.Signature signature = java.security.Signature.getInstance(getAlgorithms(rsa2));

signature.initSign(priKey);
signature.update(content.getBytes(DEFAULT_CHARSET));

byte[] signed = signature.sign();
//LogUtils.logd("AliPaySignTool.sign:加密返回");
return Base64.encode(signed);

你可能感兴趣的:(Android)