Exemplo n.º 1
0
 public static byte[] ToSHA384(this byte[] s)
 {
     using (var sha384 = new SHA384Cng())
     {
         return(sha384.ComputeHash(s));
     }
 }
Exemplo n.º 2
0
 public static byte[] ToSHA384Cng(this string s, Encoding encoding)
 {
     using (var sha384 = new SHA384Cng())
     {
         return(sha384.ComputeHash(s.GetBytes(encoding)));
     }
 }
Exemplo n.º 3
0
        public byte[] ComputeHash(byte[] abData, HashAlgorithmName HashAlgorithm)
        {
            byte[] abReturn = null;

            if (HashAlgorithm == HashAlgorithmName.MD5)
            {
                abReturn = _MD5Services.ComputeHash(abData);
            }
            else if (HashAlgorithm == HashAlgorithmName.SHA1)
            {
                abReturn = _SHA1Services.ComputeHash(abData);
            }
            else if (HashAlgorithm == HashAlgorithmName.SHA256)
            {
                abReturn = _SHA256Services.ComputeHash(abData);
            }
            else if (HashAlgorithm == HashAlgorithmName.SHA384)
            {
                abReturn = _SHA384Services.ComputeHash(abData);
            }
            else if (HashAlgorithm == HashAlgorithmName.SHA512)
            {
                abReturn = _SHA512Services.ComputeHash(abData);
            }

            return(abReturn);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Hash the data passed using the hash size specified defaulting to 256 if nothing is specified.
        /// </summary>
        /// <param name="data">The data to get a hash value (signature).</param>
        /// <param name="hashSize">The hash size to use (1, 256, 384 or 512)</param>
        /// <returns>A Byte[] the is a unique signature of the data passed.</returns>
        public static Byte[] SHACngHash(Byte[] data, Int32 hashSize)
        {
            Byte[] lHash = null;

            if (data != null)
            {
                if (hashSize == 512)
                {
                    using (SHA512Cng sha = new SHA512Cng()) { lHash = sha.ComputeHash(data); }
                }
                else if (hashSize == 384)
                {
                    using (SHA384Cng sha = new SHA384Cng()) { lHash = sha.ComputeHash(data); }
                }
                else if (hashSize == 256)
                {
                    using (SHA256Cng sha = new SHA256Cng()) { lHash = sha.ComputeHash(data); }
                }
                else
                {
                    using (SHA1Cng sha = new SHA1Cng()) { lHash = sha.ComputeHash(data); }
                }
            }

            return(lHash);
        }
Exemplo n.º 5
0
 public static String ComputeSHA384(byte[] bytes)
 {
     using (var hashAlgorithmImpl = new SHA384Cng())
     {
         var hashBytes = hashAlgorithmImpl.ComputeHash(bytes);
         return(String.Concat(hashBytes.Select(b => b.ToString("x2"))));
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Generates a 384-bit hash for the given data and returns the generated results as a Base-64 string.
 /// </summary>
 /// <param name="Data">The data to be hashed. Takes a string.</param>
 /// <returns>Hash value formatted as a Base-64 string.</returns>
 public static string Compute384Base64(string Data)
 {
     return(Convert.ToBase64String(SHA384.ComputeHash(System.Text.Encoding.Default.GetBytes(Data))));
 }
Exemplo n.º 7
0
        public BDCrypto(string Password)
        {
            if (!Info.Moduls.Contains("Crypto/BDCrypto.cs"))
            {
                Info.Moduls.Add("Crypto/BDCrypto.cs");
            }

            OneKeyHasher Translator = new OneKeyHasher();

            Encryption = new Dictionary <byte, byte>();
            Decryption = new Dictionary <byte, byte>();

            byte[] TMPStore;

            using (SHA384Cng Seg2 = new SHA384Cng())
                using (HMACSHA384 Seg1 = new HMACSHA384(Encoding.UTF32.GetBytes(Password)))
                {
                    Seg1.Initialize();
                    Translator.TheHashSize    = 512;
                    Translator.TheCharsetUsed = Encoding.UTF8;
                    TMPStore = Translator.Hash(Password);

                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    Seg1.TransformBlock(TMPStore, 0, TMPStore.Length, TMPStore, 0);
                    TMPStore = Seg1.TransformFinalBlock(TMPStore, 0, TMPStore.Length);
                    TMPStore = Seg2.ComputeHash(TMPStore);
                }

            Translator.TheCharsetUsed = Encoding.Unicode;
            Translator.TheHashSize    = 255;
            TMPStore = Translator.Hash(TMPStore);

            int  pos = 0;
            byte tmp = 0;

            while (true)
            {
                if (!Encryption.ContainsValue(TMPStore[pos]) && !Decryption.ContainsKey(TMPStore[pos]))
                {
                    Encryption.Add(tmp, TMPStore[pos]);
                    Decryption.Add(TMPStore[pos], tmp);
                    if (tmp == 255)
                    {
                        break;
                    }
                    else
                    {
                        tmp++;
                    }
                }

                pos++;
                if (pos == TMPStore.Length)
                {
                    TMPStore = Translator.Hash(TMPStore);
                    pos      = 0;
                }
            }

            _Key   = new byte[256];
            Layers = 5;

            byte x = 0;

            while (true)
            {
                _Key[x] = Encryption[x];
                if (x == 255)
                {
                    break;
                }
                else
                {
                    x++;
                }
            }
        }