예제 #1
0
        public static string ToBase64String(string value, Encoding encoding, bool omitPaddingCharacters = true)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            var valueBuffer = encoding.GetBytes(value);

            return(Base64Encoding.ToBase64String(valueBuffer, omitPaddingCharacters));
        }
예제 #2
0
        public static string FromBase64StringToEncoding(string value, Encoding encoding)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            var buffer = Base64Encoding.FromBase64StringToBuffer(value);

            return(encoding.GetString(buffer));
        }
예제 #3
0
        public static string ComputeHash(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("value");
            }

            var buffer = Encoding.UTF8.GetBytes(value);
            var hash   = ConcurrentMD5.ComputeHash(buffer);

            return(Base64Encoding.ToBase64String(hash));
        }
예제 #4
0
        public static string ComputeHash(Stream inputStream)
        {
            if (inputStream == null)
            {
                throw new ArgumentNullException("inputStream");
            }

            if (ConcurrentSHA1.threadLocalSHA1 == null)
            {
                ConcurrentSHA1.threadLocalSHA1 = SHA1.Create();
            }

            var hashBuffer = ConcurrentSHA1.threadLocalSHA1.ComputeHash(inputStream);

            return(Base64Encoding.ToBase64String(hashBuffer));
        }
예제 #5
0
 public static string ToBase64String(string value, bool omitPaddingCharacters = true)
 {
     return(Base64Encoding.ToBase64String(value, Encoding.UTF8, omitPaddingCharacters));
 }
예제 #6
0
 public static string FromBase64StringToUTF8(string value)
 {
     return(Base64Encoding.FromBase64StringToEncoding(value, Encoding.UTF8));
 }