上下文:VS 2015 winforms,Windows 7,使用 SecurityDriven Inferno 库。
我正在编写一个离线应用程序,它生成要作为电子邮件附件发送的加密文件(因此不在客户端-服务器上下文中使用)。这些文件首先使用 Inferno(ETM_Transform) 加密,然后与另一个文件(有时用于重置密码)一起发送,处理 DHM 密钥交换。
每个用户的公钥存储在应用程序创建和持久化的数据表中,允许在密钥交换过程中快速访问。然而,对于私钥,我的问题是用户(包括我自己)更愿意从密码短语中重新创建他们的私钥,从而无需隐藏密钥,从而提高安全性和可移植性。所以我需要从存储的公钥和散列密码短语中构建一个密钥。
这是一种合理的方法,还是对于这种特定情况有更好的方法?
这是一个抛出异常的非常简短的代码示例:“不支持请求的操作”。我应该如何继续将数据导入密钥?
internal static void CreateKey(string passPhrase)
{
byte[] keyType = new byte[] { 0x45, 0x43, 0x4B, 0x34 };
byte[] keyLength = new byte[] { 0x30, 0x0, 0x0, 0x0 };
CryptoRandom cr = new CryptoRandom(); // rng used for this example
byte[] prKey = cr.NextBytes(48); // salt+hash passphrase and pass it to the private key part
byte[] pbKey = cr.NextBytes(96); // the public part, if I understand the format correctly for a cngkey using ECDH_P384
byte[] blob = Utils.Combine(keyType, keyLength); // same as concat
blob = Utils.Combine(blob, pbKey, prKey);
CngKey key = CngKey.Import(blob, CngKeyBlobFormat.EccPrivateBlob);
}