Esempio n. 1
0
        private byte[] ComputeHMACMD5HashByPassword(byte[] buf)
        {
            var hmacMd5 = new System.Security.Cryptography.HMACMD5(Encoding.UTF8.GetBytes(Password));

            byte[] encCha = hmacMd5.ComputeHash(buf);
            hmacMd5.Clear();
            return(encCha);
        }
Esempio n. 2
0
        //CRAM-MD5で返す文字列を計算する
        private static string CreateCramMd5ResponseString(string challenge, string username, string password)
        {
            //デコードする
            byte[] decCha = Convert.FromBase64String(challenge);
            //passwordをキーとしてHMAC-MD5で暗号化する
            System.Security.Cryptography.HMACMD5 hmacMd5 = new System.Security.Cryptography.HMACMD5(Encoding.UTF8.GetBytes(password));
            byte[] encCha = hmacMd5.ComputeHash(decCha);
            hmacMd5.Clear();
            //16進数の文字列にする
            string hexCha = BitConverter.ToString(encCha).Replace("-", "").ToLower();

            //usernameを付ける
            hexCha = username + " " + hexCha;
            //Base64で文字列にする
            return(Convert.ToBase64String(Encoding.UTF8.GetBytes(hexCha)));
        }