android 支付寶的植入 《曾經踩過的坑》
首先說一下遇到的坑及其碰到的問題
1.java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag ClassCastException: com.android.org.bouncycastle.asn1.DLSequence cannot be cast to com.android.org.bouncycastle.asn1.ASN1Integer
原因:
修改之後,發現public class SignUtils { private static final String ALGORITHM = "RSA"; private static final String SIGN_ALGORITHMS = "SHA1WithRSA"; private static final String DEFAULT_CHARSET = "UTF-8"; public static String sign(String content, String privateKey) { try { java.security.Signature signature = java.security.Signature .getInstance(SIGN_ALGORITHMS); PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(PayBase64.decode(privateKey)); KeyFactory keyf = KeyFactory.getInstance(ALGORITHM); PrivateKey priKey = keyf.generatePrivate(priPKCS8); PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(PayBase64.decode(privateKey)); KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC"); PrivateKey priKey = keyFactory.generatePrivate(privSpec); signature.initSign(priKey); signature.update(content.getBytes(DEFAULT_CHARSET)); byte[] signed = signature.sign(); return PayBase64.encode(signed); } catch (Exception e) { e.printStackTrace(); } return null; }
com.android.org.bouncycastle.jcajce.provider.asymmetric.util.ExtendedInvalidKeySpecException: unable to process key spec: java.lang.ClassCastException: com.android.org.bouncycastle.asn1.DLSequence cannot be cast to com.android.org.bouncycastle.asn1.ASN1Integer
又這個錯誤,總麼辦?
最終是因為:
最終因為傳入私鑰錯誤。需要重新生成私鑰:
2.在handler裡面接受訊息的時候,PayResult 轉換失敗,原因是你在進行
呼叫支付寶介面的時候,所傳送的引數型別不一致導致的。eg: