我有2个字节的ECDSA私有和公共密钥数组如何生成共享密钥。我发现以下java代码。我试过了
ECPublicKeyParameters otherPartyPublicKey = (ECPublicKeyParameters)PublicKeyFactory.CreateKey(publicKeyBytes);
ECPrivateKeyParameters privateKey = (ECPrivateKeyParameters) PrivateKeyFactory.CreateKey(privateKeyBytes);
IBasicAgreement aKeyAgree = AgreementUtilities.GetBasicAgreement("ECDH");
aKeyAgree.Init(privateKey);
BigInteger sharedSecret = aKeyAgree.CalculateAgreement(otherPartyPublicKey);
但我收到错误“DEF长度118对象截断55”
答案 0 :(得分:0)
以下是我解决问题的方法。主要问题是曲线规范
X9ECParameters ecP = NistNamedCurves.GetByName("P-256");
ECDomainParameters eCDomainParameters = new ECDomainParameters(ecP.Curve, ecP.G, ecP.N);
ECCurve curve = eCDomainParameters.Curve;
ECPoint q = curve.DecodePoint(publicKeyBytes);
ECPublicKeyParameters oEcPublicKeyParameters = new ECPublicKeyParameters(q, eCDomainParameters);
Console.WriteLine(new BigInteger(privateKeyBytes));
ECPrivateKeyParameters privateKey = new ECPrivateKeyParameters(new BigInteger(privateKeyBytes), eCDomainParameters);
IBasicAgreement aKeyAgree = AgreementUtilities.GetBasicAgreement("ECDH");
aKeyAgree.Init(privateKey);
BigInteger sharedSecret = aKeyAgree.CalculateAgreement(oEcPublicKeyParameters);