.setDigests(KeyProperties.DIGEST_SHA256)
.setSignaturePaddings(KeyProperties.SIGNATURE_PADDING_RSA_PKCS1)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM, KeyProperties.BLOCK_MODE_CTR,
KeyProperties.BLOCK_MODE_CBC, KeyProperties.BLOCK_MODE_ECB)
// .setBlockModes(KeyProperties.BLOCK_MODE_GCM/CTR/CBC/ECB)
.setCertificateSerialNumber(BigInteger.valueOf(1337))
.setCertificateNotBefore(start.getTime())
.setCertificateNotAfter(end.getTime())
.build();
}
KeyPairGenerator kpGenerator = KeyPairGenerator
.getInstance(SecurityConstants.TYPE_RSA,
SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
kpGenerator.initialize(spec);
KeyPair kp = kpGenerator.generateKeyPair();
Log.d(“huangxiaoguo”, "公共密钥: " + kp.getPublic().toString());
Log.d(“huangxiaoguo”, "私钥: " + kp.getPrivate().toString());
}
/**
-
签名
-
@param inputStr
-
@return
-
@throws KeyStoreException
-
@throws CertificateException
-
@throws NoSuchAlgorithmException
-
@throws IOException
-
@throws UnrecoverableEntryException
-
@throws InvalidKeyException
-
@throws SignatureException
*/
public static String signData(String inputStr) throws KeyStoreException, CertificateException,
NoSuchAlgorithmException, IOException, UnrecoverableEntryException,
InvalidKeyException, SignatureException {
byte[] data = inputStr.getBytes();
//AndroidKeyStore
KeyStore ks = KeyStore.getInstance(SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
// 如果你没有InputStream加载,你仍然需要
//称之为“负载”,或者它会崩溃
ks.load(null);
if (mAlias == null) {
setAlias(SAMPLE_ALIAS);
}
//从A