示例#1
0
        /// <summary>
        /// HMAC_SHA384
        /// </summary>
        /// <param name="srcString">The string to be encrypted</param>
        /// <param name="key">encrypte key</param>
        /// <returns></returns>
        public static string HMACSHA384(string srcString, string key)
        {
            byte[] secrectKey = Encoding.UTF8.GetBytes(key);
            using (HMACSHA384 hmac = new HMACSHA384(secrectKey))
            {
                hmac.Initialize();

                byte[] bytes_hmac_in  = Encoding.UTF8.GetBytes(srcString);
                byte[] bytes_hamc_out = hmac.ComputeHash(bytes_hmac_in);


                string str_hamc_out = BitConverter.ToString(bytes_hamc_out);
                str_hamc_out = str_hamc_out.Replace("-", "");

                return(str_hamc_out);
            }
        }
示例#2
0
        /// <summary>
        /// HMAC_SHA384
        /// </summary>
        /// <param name="srcString">The string to be encrypted</param>
        /// <param name="key">encrypte key</param>
        /// <returns></returns>
        public static string HMACSHA384(string srcString, string key)
        {
            Check.Argument.IsNotEmpty(srcString, nameof(srcString));
            Check.Argument.IsNotEmpty(key, nameof(key));

            byte[] secrectKey = Encoding.UTF8.GetBytes(key);
            using (var hmac = new HMACSHA384(secrectKey))
            {
                hmac.Initialize();

                byte[] bytes_hmac_in  = Encoding.UTF8.GetBytes(srcString);
                byte[] bytes_hamc_out = hmac.ComputeHash(bytes_hmac_in);

                string str_hamc_out = BitConverter.ToString(bytes_hamc_out);
                str_hamc_out = str_hamc_out.Replace("-", "");

                return(str_hamc_out);
            }
        }
示例#3
0
        /// <summary>
        /// HMAC_SHA384
        /// </summary>
        /// <param name="source">The string to be encrypted</param>
        /// <param name="key">encrypte key</param>
        /// <returns></returns>
        public static string A384(string source, string key)
        {
            if (string.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException(nameof(source), "");
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key), "");
            }

            using (var hmac = new HMACSHA384(Encoding.UTF8.GetBytes(key)))
            {
                hmac.Initialize();
                var strHmacOut = BitConverter.ToString(hmac.ComputeHash(Encoding.UTF8.GetBytes(source)));
                strHmacOut = strHmacOut.Replace("-", "");
                return(strHmacOut);
            }
        }
示例#4
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++;
                }
            }
        }