我已从其他设备接收到RSA公钥。 我用这些字节数组创建公钥来加密任何字符串。 但我的公钥无效。
撤回了许多问题,但我不知道为什么会这样。 请帮帮我。
步骤如下。
StringBuilder builder = new StringBuilder(); for ( byte key : mKey ) builder.append(key); byte[] keyBytes = Base64.decode(builder.toString().getBytes("utf-8"), Base64.DEFAULT); PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
mKey是公钥的字节数组。
但现在发生了异常。
例外:
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ java.security.spec.InvalidKeySpecException: java.lang.RuntimeException: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ at com.android.org.conscrypt.OpenSSLKey.getPublicKey(OpenSSLKey.java:101)
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ at com.android.org.conscrypt.OpenSSLRSAKeyFactory.engineGeneratePublic(OpenSSLRSAKeyFactory.java:47)
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ at java.security.KeyFactory.generatePublic(KeyFactory.java:171)
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ at updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator.MainActivity.processGenerateKeyForUpdate(MainActivity.java:253)
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ at updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator.MainActivity.access$1600(MainActivity.java:53)
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ at updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator.MainActivity$5.handleMessage(MainActivity.java:411)
03-23 15:23:53.468 5641-5641/updator.firmware.mpaio.samilcts.com.mpaiofirmwareupdator W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
比照 收到PublicKey字节数组:
谢谢。' 0x47,0x95,0x1a,0xe6,0xf1,0xba,0x31,0x3b,0x73,0xc7,0x79, 0x75,0x72,0xc6,0x6d,0xcc,0xf0,0x6b,0x0f,0xfa,0x16,0x0e, 0xed,0x2d,0x85,0xeb,0x17,0x89,0x91,0x83,0x59,0x64,0xda, 0x04,0x69,0x31,0x45,0x16,0x73,0x1b,0x46,0xab,0xe0,0x2d, 0x6e,0xda,0x7d,0x51,0xc9,0x2b,0xc6,0xe9,0x73,0x19,0x2e, 0x3d,0x39,0x12,0xd6,0x44,0xf8,0x71,0xe0,0x49,0xc4,0x54, 0xd5,0xd1,0xe9,0x1f,0x03,0x6f,0xd6,0x2b,0xf9,0x77,0xd8, 0x83,0x7e,0x9d,0x1d,0xf7,0x46,0x5d,0xf4,0xac,0x9f,0x6b, 0xe7,0x2a,0x68,0xb9,0x55,0x01,0xd3,0xde,0xbb,0x1b,0x93, 0x3b,0x0a,0x78,0xe2,0x06,0x1c,0x5d,0x18,0x61,0x2d,0x8f, 0x23,0x4e,0x3c,0xbb,0x35,0xa5,0x99,0xb4,0x2f,0x9b,0x9d, 0x2b,0x67,0xfb,0x89,0xba,0x1c,0x8f,0x48,0x9c,0xa7,0x99, 0x5d,0xa0,0x11,0xe6,0x1d,0x5a,0xd2,0x18,0x03,0xc5,0x98, 0xf5,0x26,0xb2,0x14,0xaa,0xfd,0x77,0x8e,0x78,0x36,0xc4, 0x46,0xb2,0xea,0xd0,0xa2,0x5d,0xb9,0xc5,0xae,0x47,0x17, 0xc1,0x93,0x42,0x12,0x9c,0x3a,0xa0,0x71,0xb5,0x32,0x51, 0x74,0xa0,0x6d,0x2b,0xbe,0xc8,0x4f,0xc4,0xf3,0x5f,0xd3, 0x4f,0x6b,0xf9,0x7a,0x5d,0xfa,0x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