我尝试使用其他公共密钥和私有密钥创建sharedKey,但是我遇到了异常。
byte[] otherPublicKey = mOtherPublic.getBytes();
X509EncodedKeySpec pkSpec = new X509EncodedKeySpec(otherPublicKey);
KeyFactory keyFactory = KeyFactory.getInstance("EC");
PublicKey otherPublicKey = keyFactory.generatePublic(pkSpec);//in this line i faced to exception
// Perform key agreement
KeyAgreement keyAgreement = KeyAgreement.getInstance("ECDH");
keyAgreement.init(mkeyPair.getPrivate());
keyAgreement.doPhase(otherPublicKey, true);
// Read shared secret
byte[] sharedSecret = keyAgreement.generateSecret();