InputStream is = this.getAssets().open(fileName);//证书读取流

CertificateFactory cf = CertificateFactory.getInstance("X.509");//获取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);/* 要加密的字符串进行编码 */
byte[] doFinal = tcsCipher.doFinal(encode);/*加密*/
String tcsEncryptPassword = Base64.encodeToString(doFinal, Base64.DEFAULT);/* 将加密后的字符串进行编码 */

  

  

相关文章:

  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2022-02-17
  • 2021-10-13
猜你喜欢
  • 2021-09-05
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案