Beispiel #1
0
        /// <summary> decodes a string to byte array</summary>
        public static byte[] decodeToByte(String str)
        {
            if (str == null)
            {
                return(null);
            }

            // QCR 740918 if we have and empty expression it is sent from the server as empty string
            // and changed locally to a string with one blank either way they are not valid base64 encoded
            // string and should not be decoded.
            if (str.Equals("") || str.Equals(" "))
            {
                return(new byte[0]);
            }

            try
            {
                Encoding base64Encoding = ISO_8859_1_Encoding.getInstance();
                return(decode(base64Encoding.GetBytes(str)));
            }
            catch (Exception uee)
            {
                throw new ApplicationException(uee.Message);
            }
        }
Beispiel #2
0
        /// <summary> Encodes string using the base64-encoding.
        /// If isUseEnvCharset is true, use the specific charset when converting
        /// string to byte array. (DBCS support)
        /// </summary>
        /// <param name="str">the string </param>
        /// <param name="isUseEnvCharset"> </param>
        /// <param name="encoding"> Environment.Encoding </param>
        /// <returns> the base64-encoded str </returns>
        public static String encode(String str, bool isUseEnvCharset, Encoding encoding)
        {
            if (str == null)
            {
                return(null);
            }
            if (str.Equals(""))
            {
                return(str);
            }

            try
            {
                Encoding base64Encoding = ISO_8859_1_Encoding.getInstance();
                Encoding srcEncoding    = isUseEnvCharset ? encoding : base64Encoding;
                byte[]   ba             = encode(srcEncoding.GetBytes(str));
                return(base64Encoding.GetString(ba, 0, ba.Length));
            }
            catch (Exception uee)
            {
                throw new ApplicationException(uee.Message);
            }
        }
Beispiel #3
0
        /// <summary> This method decodes the given string using the base64-encoding
        /// specified in RFC-2045 (Section 6.8).
        /// </summary>
        /// <param name="str">the base64-encoded string. </param>
        /// <param name="encoding">Environment.Encoding or null.</param>
        /// <returns> the decoded str.</returns>
        public static String decode(String str, Encoding encoding)
        {
            if (str == null)
            {
                return(null);
            }

            if (str.Equals(""))
            {
                return(str);
            }
            try
            {
                Encoding base64Encoding = ISO_8859_1_Encoding.getInstance();
                byte[]   ba             = decode(base64Encoding.GetBytes(str));
                Encoding destEncoding   = (encoding != null) ? encoding : base64Encoding;
                return(destEncoding.GetString(ba, 0, ba.Length));
            }
            catch (Exception uee)
            {
                throw new ApplicationException(uee.Message);
            }
        }