1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
InputStream is = this .getAssets().open(fileName);
CertificateFactory cf = CertificateFactory.getInstance( "X.509" );
X509Certificate certificate = (X509Certificate) cf.generateCertificate(is);
PublicKey publicKey = certificate.getPublicKey();
Cipher tcsCipher = Cipher.getInstance(publicKey.getAlgorithm());
tcsCipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte [] encode = Base64.encode( "123" .getBytes(),Base64.DEFAULT); <br>
byte [] doFinal = tcsCipher.doFinal(encode); <br>
String tcsEncryptPassword = Base64.encodeToString(doFinal, Base64.DEFAULT);
|