.NET使用OpenSSL生成的pem密钥文件(增加size为2048的密钥转换)(4)
Array.Copy(keyData,index, pemExponent1, 0, pemExponent1.Length);
index += pemExponent1.Length;
index += (keySize1024 ? ((int)keyData[index + 1] == 64 ? 2 : 3) : ((int)keyData[index + 2] == 128 ? 3 : 4));
byte[] pemExponent2 = (keySize1024 ? new byte[64] : new byte[128]);
Array.Copy(keyData, index, pemExponent2, 0, pemExponent2.Length);
index += pemExponent2.Length;
index += (keySize1024 ? ((int)keyData[index + 1] == 64 ? 2 : 3) : ((int)keyData[index + 2] == 128 ? 3 : 4));
byte[] pemCoefficient = (keySize1024 ? new byte[64] : new byte[128]);
Array.Copy(keyData, index, pemCoefficient, 0, pemCoefficient.Length);
RSAParameters para = new RSAParameters();
para.Modulus = pemModulus;
para.Exponent = pemPublicExponent;
para.D = pemPrivateExponent;
para.P = pemPrime1;
para.Q = pemPrime2;
para.DP = pemExponent1;
para.DQ = pemExponent2;
para.InverseQ = pemCoefficient;
return para;
}
}
}
测试加、解密,签名验证功能通过:
static void Main(string[] args)
{
string privateKey = GetPemContent(@"C:\ftzl\privatekey2048.pem");
string publicKey = GetPemContent(@"c:\ftzl\publickey2048.pem");
//DebugRsaKey(privateKey,true);
TestSignAndEncrypt(privateKey,publicKey);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>