c# - CngAlgorithm.ECDiffieHellmanP521/P256/P384生成的EccPrivateBlob的CngKeyBlobFormat是什么?
问题描述
CngKey key = CngKey.Create(CngAlgorithm.ECDiffieHellmanP521, null,
new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextExport });
byte[] keyBlob= key.Export(CngKeyBlobFormat.EccPrivateBlob);
keyBlob 的长度是 206。它的格式是什么?哪些字节是 32 字节私钥和 64 字节公钥?
在将公钥从其他地方导入到 CngKey?,长度为4+4+64+32=104。
解决方案
对于所有三个曲线,blob 的二进制结构都是相同的:
<magic number, 4 bytes><modulus length in bytes, 4 bytes><x-value of public key><y-value of public key><private key>
详细适用:
secp256r1 / NIST P-256
Private: 45434B32 20000000 <x-value of public key, 32 bytes><y-value of public key, 32 bytes><private key, 32 bytes> total length: 104 bytes Public: 45434B31 20000000 <x-value of public key, 32 bytes><y-value of public key, 32 bytes> total length: 72 bytes
secp384r1 / NIST P-384
Private: 45434B34 30000000 <x-value of public key, 48 bytes><y-value of public key, 48 bytes><private key, 48 bytes> total length: 152 bytes Public: 45434B33 30000000 <x-value of public key, 48 bytes><y-value of public key, 48 bytes> total length: 104 bytes
secp521r1 / NIST P-521
Private: 45434B36 42000000 <x-value of public key, 66 bytes><y-value of public key, 66 bytes><private key, 66 bytes> total length: 206 bytes Public: 45434B35 42000000 <x-value of public key, 66 bytes><y-value of public key, 66 bytes> total length: 140 bytes
私钥和公钥的x
- 和 -y
组件以大端格式存储。所有三个分量都具有模数的长度。因此,斑点的不同长度是由曲线的不同模量引起的。
另请参阅:SECG、SEC2、密钥 blob 格式、幻数、ECCPublicBlob 和 ECCPrivateBlob 的格式
推荐阅读
- c++ - C++ 中的 Playsound() 播放 windows 错误声音,我已经包含了 winmm.lib
- webassembly - 生成的 WebAssembly 模块如何包含大量动态数据
- javascript - 在每个循环后使用 ajax 调用调用一个函数
- react-native - React-native-maps MapView.Circle
- php - php中数组键上的连字符
- python - Pandas:在测试中处理看不见的数据
- google-chrome-extension - Chrome 扩展程序(和/或 tampermonkey 脚本)未在某些网站(如 gmail)上运行
- android - Android:如何从屏蔽广告的数量和网络带宽消耗来衡量广告屏蔽的效果?
- c - 如何获取 SSDT 地址
- ios - 如何知道 Firebase 是否获取了值