Beispiel #1
0
        public static string Encrypt(string text)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            byte[] textBytes = encoding.GetBytes(text + HexMD5.Encode(KeyPairs.KEY_PAIR_1));
            byte[] keyBytes  = encoding.GetBytes(HexMD5.Encode(KeyPairs.KEY_PAIR_2));

            int length = textBytes.Length > keyBytes.Length ? keyBytes.Length : textBytes.Length;

            for (int i = 0; i < length; i++)
            {
                textBytes[i] += keyBytes[i];
            }


            Base64Encoder base64Encoder = new Base64Encoder(textBytes);

            byte[] encodedBytes = encoding.GetBytes(base64Encoder.GetEncoded());


            return(encoding.GetString(encodedBytes));
        }
Beispiel #2
0
        public static string Decrypt(string text)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] keyBytes = encoding.GetBytes(HexMD5.Encode(KeyPairs.KEY_PAIR_2));

            byte[]        encodedTextBytes = encoding.GetBytes(text);
            Base64Decoder base64Decoder    = new Base64Decoder(encoding.GetChars(encodedTextBytes));

            byte[] decodedBytes = base64Decoder.GetDecoded();



            int length = decodedBytes.Length > keyBytes.Length ? keyBytes.Length : decodedBytes.Length;

            for (int i = 0; i < length; i++)
            {
                decodedBytes[i] -= keyBytes[i];
            }

            string decodedText = encoding.GetString(decodedBytes);

            return(decodedText.Substring(0, decodedText.Length - HexMD5.Encode(KeyPairs.KEY_PAIR_1).Length));
        }