我想获得 ECDH 密钥对(公钥和私钥)。此方法在 Android 9.0 pie 中不起作用,因为从该版本中删除了安全提供程序 "BC" 、 "SC"。我尝试了以下方法
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC", "BC");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
keyGen.initialize(256, random);
KeyFactory kaif = KeyFactory.getInstance("EC", "BC");
KeyPair pair = keyGen.generateKeyPair();
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();
Following is the key which i got when using "BC" provider with the bove code, EC Private Key S: 30e3def89f6aca7ab4e1e0e0367bf936955339db03a0c32c63a08293066f9423 EC Public Key X: 1675a6b1c8097f651be6f6a555ab9e5da83f03d3082041ae29111609b98594be Y: ed23f9263c6a1e8892d03a0c33ed9d8bfc5886dfe67fb7947457e3ff43baffca
方法二:Security.insertProviderAt(BouncyCastleProvider(), 1);
当我在 gradle 中添加 Bouncy castle 并尝试像上面一样启动时,输出如下 privateKey = {OpenSSLECPrivateKey@7518} "OpenSSLECPrivateKey{params={ECDSA-Parameters: (256 bit)\n}}" publicKey = {OpenSSLECPublicKey@7519} “公钥:(256 位)\n00000000 04 5c 2c 76 23 09 41 c4 16 e2 99 ea e0 fa ed 16 |.\,v#.A.........|\n00000010 52 ca 91 d2 0c fe 7f c4 94 76 54 9a 3c 49 ab a5 |R........vT.
我需要它以可读格式像上面一样简单,我是否需要进行任何转换才能获得字母数字键