RSA公钥格式PKCS#1,PKCS#8互转(微信获取RSA加密公钥)

时间:2024-04-17 16:19:54
       //把RSA公钥格式PKCS#1转换成PKCS#8
org.bouncycastle.asn1.pkcs.RSAPublicKey rsaPublicKey = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(
org.bouncycastle.util.encoders.Base64.decode(publicKeyString));

        java.security.spec.RSAPublicKeySpec publicKeySpec = new java.security.spec.RSAPublicKeySpec(rsaPublicKey.getModulus(), rsaPublicKey.getPublicExponent());

        java.security.KeyFactory keyFactory = java.security.KeyFactory.getInstance("RSA");

        java.security.PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);

RSA公钥格式PKCS#1,PKCS#8互转说明(命令的方式)

  1. PKCS#1 转 PKCS#8:

openssl rsa -RSAPublicKey_in -in <filename> -pubout

  1. PKCS#8 转 PKCS#1:

openssl rsa -pubin -in <filename> -RSAPublicKey_out


  1. PKCS#1 格式密钥:

-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEArT82k67xybiJS9AD8nNAeuDYdrtCRaxkS6cgs8L9h83eqlDTlrdw
zBVSv5V4imTq/URbXn4K0V/KJ1TwDrqOI8hamGB0fvU13WW1NcJuv41RnJVua0QA
lS3tS1JzOZpMS9BEGeFvyFF/epbi/m9+2kUWG94FccArNnBtBqqvFncXgQsm98JB
3a62NbS1ePP/hMI7Kkz+JNMyYsWkrOUFDCXAbSZkWBJekY4nGZtK1erqGRve8Jbx
TWirAm/s08rUrjOuZFA21/EI2nea3DidJMTVnXVPY2qcAjF+595shwUKyTjKB8v1
REPB3hPF1Z75O6LwuLfyPiCrCTmVoyfqjwIDAQAB
-----END RSA PUBLIC KEY-----


  1. PKCS#8 格式密钥:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArT82k67xybiJS9AD8nNA
euDYdrtCRaxkS6cgs8L9h83eqlDTlrdwzBVSv5V4imTq/URbXn4K0V/KJ1TwDrqO
I8hamGB0fvU13WW1NcJuv41RnJVua0QAlS3tS1JzOZpMS9BEGeFvyFF/epbi/m9+
lkUWG94FccArNnBtBqqvFncXgQsm98JB3a42NbS1ePP/hMI7Kkz+JNMyYsWkrOUF
DCXAbSZkWBJekY4nGZtK1erqGRve8JbxTWirAm/s08rUrjOuZFA21/EI2nea3Did
JMTVnXVPY2qcAjF+595shwUKyTjKB8v1REPB3hPF1Z75O6LwuLfyPiCrCTmVoyfq
jwIDAQAB
-----END PUBLIC KEY-----

 

 

微信企业付款到银行卡(包含获取微信端的RSA公钥)参考文章:

https://www.jianshu.com/p/efb1dcce6e4a