Пример #1
0
 private static RSAParameters GetPublicKey(string id, bool tmpKey, Func<RSAParameters> loader)
 {
     var rsaKey = GetRsaKey(id);
     if (!Equals(rsaKey, default(RsaKey)))
         return new RSAParameters
         {
             Modulus = rsaKey.Modulus.Hex2Bytes(),
             Exponent = rsaKey.Exponent.Hex2Bytes()
         };
     var privateKey = loader();
     rsaKey = new RsaKey
     {
         Id = id,
         TmpKey = tmpKey,
         Modulus = privateKey.Modulus.Bytes2Hex(),
         Exponent = privateKey.Exponent.Bytes2Hex(),
         D = privateKey.D.Bytes2Hex(),
         Dp = privateKey.DP.Bytes2Hex(),
         Dq = privateKey.DQ.Bytes2Hex(),
         InverseQ = privateKey.InverseQ.Bytes2Hex(),
         P = privateKey.P.Bytes2Hex(),
         Q = privateKey.Q.Bytes2Hex()
     };
     MongoDbBase<RsaKey>.Default.SaveMongo(rsaKey, "RSA", "RSA", null);
     return new RSAParameters
     {
         Modulus = rsaKey.Modulus.Hex2Bytes(),
         Exponent = rsaKey.Exponent.Hex2Bytes()
     };
 }
Пример #2
0
 private static RSAParameters GetPrivateKey(RsaKey rsaKey)
 {
     return new RSAParameters
     {
         Modulus = rsaKey.Modulus.Hex2Bytes(),
         Exponent = rsaKey.Exponent.Hex2Bytes(),
         D = rsaKey.D.Hex2Bytes(),
         DP = rsaKey.Dp.Hex2Bytes(),
         DQ = rsaKey.Dq.Hex2Bytes(),
         InverseQ = rsaKey.InverseQ.Hex2Bytes(),
         P = rsaKey.P.Hex2Bytes(),
         Q = rsaKey.Q.Hex2Bytes()
     };
 }