生成的 ECDsaCng 密钥长于预期的 32 字节
ECDsaCng key generated longer than expected 32-bytes
我在摆弄 ECDsaCng,发现密钥大小似乎不正确。从下面的代码来看,privateKey 变量,例如,是一个 104 字节长的数组,而我没想到它会大于 32。
我做错了什么?
ECDsaCng dsa = new ECDsaCng(256);
dsa.HashAlgorithm = CngAlgorithm.Sha256;
dsa.GenerateKey(ECCurve.NamedCurves.nistP256);
var privateKey = dsa.Key.Export(CngKeyBlobFormat.EccPrivateBlob);
var publicKey = dsa.Key.Export(CngKeyBlobFormat.EccPublicBlob);
提前致谢。
私钥d
是[1, n - 1]
中的一个随机整数,其中n
是基点G
的顺序。 public键是曲线点(x, y) = d * G
、here. For NIST P-256
(secp256r1
) d
、x
和y
被编码为32字节(值不能更大)。
MS 以 here. The format for the public key has an 8 bytes header, followed by the 32 bytes x
-value and the 32 bytes y
-value, so that the total length is 72 bytes. The format for the private key has a (different) 8-byte header, followed by the 32 byte x
-value, the 32 byte y
-value, and the 32 byte d
-value, so that the total length is 104 bytes, in accordance with the value you found. A detailed description of the headers can be found here.
描述的特定格式存储这两个密钥
我在摆弄 ECDsaCng,发现密钥大小似乎不正确。从下面的代码来看,privateKey 变量,例如,是一个 104 字节长的数组,而我没想到它会大于 32。
我做错了什么?
ECDsaCng dsa = new ECDsaCng(256);
dsa.HashAlgorithm = CngAlgorithm.Sha256;
dsa.GenerateKey(ECCurve.NamedCurves.nistP256);
var privateKey = dsa.Key.Export(CngKeyBlobFormat.EccPrivateBlob);
var publicKey = dsa.Key.Export(CngKeyBlobFormat.EccPublicBlob);
提前致谢。
私钥d
是[1, n - 1]
中的一个随机整数,其中n
是基点G
的顺序。 public键是曲线点(x, y) = d * G
、here. For NIST P-256
(secp256r1
) d
、x
和y
被编码为32字节(值不能更大)。
MS 以 here. The format for the public key has an 8 bytes header, followed by the 32 bytes x
-value and the 32 bytes y
-value, so that the total length is 72 bytes. The format for the private key has a (different) 8-byte header, followed by the 32 byte x
-value, the 32 byte y
-value, and the 32 byte d
-value, so that the total length is 104 bytes, in accordance with the value you found. A detailed description of the headers can be found here.