Exemplo n.º 1
0
        private static byte[] GetIV(string containerName)
        {
            byte[] e, m = null;
            byte[] s    = Utils.StringToUTF8Bytes(Constants.CONST2);

            string xmlKey = RSACipher.ExportKeyAsXmlString(containerName);
            RSACryptoServiceProvider rsa = RSACipher.ImportKeyFromXmlString(containerName, xmlKey);

            RSACipher.QueryRsaKeyParameters(rsa, out m, out e);

            byte[] h3       = HashControl.GetSHA512ManagedHash(m, e);
            string h3Base64 = Utils.BytesToBase64String(h3);

            return(HashControl.DerivePasswordBytes(h3Base64, h3, 32));
        }
Exemplo n.º 2
0
        private static byte[] GetKey(string containerName)
        {
            byte[] d, p, q = null;
            byte[] s       = Utils.StringToUTF8Bytes(Constants.CONST1);

            string xmlKey = RSACipher.ExportKeyAsXmlString(containerName);
            RSACryptoServiceProvider rsa = RSACipher.ImportKeyFromXmlString(containerName, xmlKey);

            RSACipher.QueryRsaKeyParameters(rsa, out d, out p, out q);

            byte[] h1 = HashControl.GetSHA512ManagedHash(d, p);
            byte[] h2 = HashControl.GetSHA512ManagedHash(q, s);

            string h1Base64 = Utils.BytesToBase64String(h1);

            return(HashControl.DerivePasswordBytes(h1Base64, h2, 32));
        }
Exemplo n.º 3
0
 public static RSACryptoServiceProvider ImportKeyFromXmlString(string containerName, string xmlKeyString)
 {
     return(RSACipher.ImportKeyFromXmlString(containerName, xmlKeyString));
 }
Exemplo n.º 4
0
 public static string ExportKeyAsXmlString(string containerName, bool includePrivateKeyInfo = true)
 {
     return(RSACipher.ExportKeyAsXmlString(containerName, includePrivateKeyInfo));
 }
Exemplo n.º 5
0
        public static void ImportKeyFromXmlFile(string filePath, string containerName)
        {
            string xmlKey = Utils.ReadStringFromFile(filePath);

            RSACipher.ImportKeyFromXmlString(containerName, xmlKey);
        }
Exemplo n.º 6
0
        public static void ExportKeyAsXmlFile(string filePath, string containerName, bool includePrivateKeyInfo = true)
        {
            string xmlKey = RSACipher.ExportKeyAsXmlString(containerName, true);

            Utils.WriteStringToFile(xmlKey, filePath);
        }