public static boolean verify(byte[] data, String publicKey, String sign) throws Exception { byte[] keyBytes = Base64Utils.decode(publicKey); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); PublicKey publicK = keyFactory.generatePublic(keySpec); Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); signature.initVerify(publicK); signature.update(data); return signature.verify(Base64Utils.decode(sign)); } /** * 读取密钥信息 * * @param in * @return * @throws IOException */ public static String readKey(InputStream in) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(in)); String readLine = null; StringBuilder sb = new StringBuilder(); while ((readLine = br.readLine()) != null) { if (readLine.charAt(0) == ‘-‘) { continue; } else { sb.append(readLine); sb.append(‘\r’); } }
return sb.toString(); } InputStream inPrivate = getResources().getAssets().open("pkcs8_rsa_private_key.pem"); String s1 = RSAUtils.readKey(inPrivate);http://blog.csdn.net/mq2856992713/article/details/52587254 http://www.jianshu.com/p/8747d01a0450 http://blog.csdn.net/jdsjlzx/article/details/41441147