Пример #1
0
 internal static string CreateHash(IHashProvider provider, string plaintext)
 {
     byte[] bytes   = Encoding.Unicode.GetBytes(plaintext);
     byte[] inArray = provider.CreateHash(bytes);
     CryptographyUtility.GetRandomBytes(bytes);
     return(Convert.ToBase64String(inArray));
 }
Пример #2
0
        internal static bool CompareHash(IHashProvider provider, string plaintext, string hashedText)
        {
            byte[] bytes      = Encoding.Unicode.GetBytes(plaintext);
            byte[] hashedtext = Convert.FromBase64String(hashedText);
            bool   flag       = provider.CompareHash(bytes, hashedtext);

            CryptographyUtility.GetRandomBytes(bytes);
            return(flag);
        }
Пример #3
0
 void AddSaltToPlainText(ref byte[] salt, ref byte[] plaintext)
 {
     if (this.saltEnabled)
     {
         if (salt == null)
         {
             salt = CryptographyUtility.GetRandomBytes(0x10);
         }
         plaintext = CryptographyUtility.CombineBytes(salt, plaintext);
     }
 }
Пример #4
0
 internal static string EncryptSymmetric(ISymmetricCryptoProvider provider, string plaintext)
 {
     if (string.IsNullOrEmpty(plaintext))
     {
         throw new ArgumentException("The value can not be a null or empty string.", "plaintext");
     }
     byte[] bytes   = Encoding.Unicode.GetBytes(plaintext);
     byte[] inArray = provider.Encrypt(bytes);
     CryptographyUtility.GetRandomBytes(bytes);
     return(Convert.ToBase64String(inArray));
 }
Пример #5
0
        internal static string DecryptSymmetric(ISymmetricCryptoProvider provider, string ciphertextBase64)
        {
            if (string.IsNullOrEmpty(ciphertextBase64))
            {
                throw new ArgumentException("The value can not be a null or empty string.", "ciphertextBase64");
            }
            byte[] ciphertext = Convert.FromBase64String(ciphertextBase64);
            byte[] bytes      = provider.Decrypt(ciphertext);
            string str        = Encoding.Unicode.GetString(bytes);

            CryptographyUtility.GetRandomBytes(bytes);
            return(str);
        }
Пример #6
0
 byte[] GenerateSalt()
 {
     return(CryptographyUtility.GetRandomBytes(0x10));
 }