在 BouncyCastle 中导入 public/private 个 ECDH 密钥
Import public/private ECDH keys in BouncyCastle
我正在尝试在 BouncyCastle 中导入 public 和 ECDH 私钥。要导入 public 密钥,我使用下面的 C# 代码并且代码工作正常:
byte[] pc = HexStringToByteArray(PUBLIC_KEY);
var ecdp = TlsEccUtilities.GetParametersForNamedCurve(NamedCurve.secp256r1);
var basePoint = TlsEccUtilities.ValidateECPublicKey(TlsEccUtilities.DeserializeECPublicKey(null, ecdp, pc));
SubjectPublicKeyInfo subinfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(basePoint);
ECPublicKeyParameters publicKey = (ECPublicKeyParameters)PublicKeyFactory.CreateKey(subinfo);
public 键:
042e3e5ccf6b9ab04be7a22f3faccfde73c87e87155394a34815408a896ca18a374dac669af3bf6220fc863767f4af47507c5bc221fc4a19874daf39b4074e3eb8
私钥:
be3f9bff87973356d04dad279e21535925c3656db011c9ae76b5a7f09ef8d9de
但是我找不到导入私钥的解决方案。你能帮我解决这个问题吗?
Finlay 我找到了解决方案:
// Import public key
byte[] pc = HexStringToByteArray(PUBLIC_KEY);
var ecdp = TlsEccUtilities.GetParametersForNamedCurve(NamedCurve.secp256r1);
var basePoint = TlsEccUtilities.ValidateECPublicKey(TlsEccUtilities.DeserializeECPublicKey(null, ecdp, pc));
SubjectPublicKeyInfo subinfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(basePoint);
ECPublicKeyParameters publicKey = (ECPublicKeyParameters)PublicKeyFactory.CreateKey(subinfo);
// Import private key
BigInteger bi = new BigInteger(HexStringToByteArray(PRIVATE_KEY));
ECPrivateKeyParameters privateKey = new ECPrivateKeyParameters(bi, publicKey.Parameters);
我正在尝试在 BouncyCastle 中导入 public 和 ECDH 私钥。要导入 public 密钥,我使用下面的 C# 代码并且代码工作正常:
byte[] pc = HexStringToByteArray(PUBLIC_KEY);
var ecdp = TlsEccUtilities.GetParametersForNamedCurve(NamedCurve.secp256r1);
var basePoint = TlsEccUtilities.ValidateECPublicKey(TlsEccUtilities.DeserializeECPublicKey(null, ecdp, pc));
SubjectPublicKeyInfo subinfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(basePoint);
ECPublicKeyParameters publicKey = (ECPublicKeyParameters)PublicKeyFactory.CreateKey(subinfo);
public 键: 042e3e5ccf6b9ab04be7a22f3faccfde73c87e87155394a34815408a896ca18a374dac669af3bf6220fc863767f4af47507c5bc221fc4a19874daf39b4074e3eb8
私钥: be3f9bff87973356d04dad279e21535925c3656db011c9ae76b5a7f09ef8d9de
但是我找不到导入私钥的解决方案。你能帮我解决这个问题吗?
Finlay 我找到了解决方案:
// Import public key
byte[] pc = HexStringToByteArray(PUBLIC_KEY);
var ecdp = TlsEccUtilities.GetParametersForNamedCurve(NamedCurve.secp256r1);
var basePoint = TlsEccUtilities.ValidateECPublicKey(TlsEccUtilities.DeserializeECPublicKey(null, ecdp, pc));
SubjectPublicKeyInfo subinfo = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(basePoint);
ECPublicKeyParameters publicKey = (ECPublicKeyParameters)PublicKeyFactory.CreateKey(subinfo);
// Import private key
BigInteger bi = new BigInteger(HexStringToByteArray(PRIVATE_KEY));
ECPrivateKeyParameters privateKey = new ECPrivateKeyParameters(bi, publicKey.Parameters);