Example #1
0
        /// <summary>
        /// Modified Base64 for URL applications ('base64url' encoding)
        ///
        /// See http://tools.ietf.org/html/rfc4648
        /// For more information see http://en.wikipedia.org/wiki/Base64
        /// </summary>
        /// <param name="input"></param>
        /// <returns>Input byte array converted to a base64ForUrl encoded string</returns>
        public static string ToBase64ForUrlString(byte[] input)
        {
            string ret = Convert.ToBase64String(input);

            ret = Base64Old.EscapeString(ret);
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Modified Base64 for URL applications ('base64url' encoding)
        ///
        /// See http://tools.ietf.org/html/rfc4648
        /// For more information see http://en.wikipedia.org/wiki/Base64
        /// </summary>
        /// <param name="base64ForUrlInput"></param>
        /// <returns>Input base64ForUrl encoded string as the original byte array</returns>
        public static byte[] FromBase64ForUrlString(string input)
        {
            string temp = Base64Old.UnEscapeString(input);

            byte[] ba = Convert.FromBase64String(temp);

            return(ba);
        }
Example #3
0
        /// <summary>
        /// Encodes the GUID with the specified encoding.  This method will throw an exception if it fails for any reason.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <param name="encoding">The encoding.</param>
        /// <returns>System.String</returns>
        public static string Encode(Guid guid, GuidEncoding encoding)
        {
            switch (encoding)
            {
            case GuidEncoding.Base32:
                return(Base32Url.ToBase32String(guid.ToByteArray()));

            case GuidEncoding.Base64:
                return(Base64Url.ToBase64ForUrlString(guid.ToByteArray()));

            case GuidEncoding.Base64Old:
                return(Base64Old.ToBase64ForUrlString(guid.ToByteArray()));

            default:
                throw new Exception("The encoding type is not supported!");
            }
        }
Example #4
0
        /// <summary>
        /// Decodes the specified string containing a GUID.  This will throw an exception if it isn't a supported
        /// encoding of a GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <param name="encoding">The encoding method to use.</param>
        /// <returns>System.Guid</returns>
        public static Guid Decode(string guid, GuidEncoding encoding)
        {
            switch (encoding)
            {
            case GuidEncoding.Base32:
                return(new Guid(Base32Url.FromBase32String(guid)));

            case GuidEncoding.Base64:
                return(new Guid(Base64Url.FromBase64ForUrlString(guid)));

            case GuidEncoding.Base64Old:
                return(new Guid(Base64Old.FromBase64ForUrlString(guid)));

            case GuidEncoding.String:
                return(new Guid(guid));

            default:
                throw new Exception("The string being passed doesn't contain a valid Guid");
            }
        }