Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Linq;
using System.Text;

namespace Action_Tire_Payment_Processor
{
    public static class Encryption
    {
        public static string rsaRgb = "MADBBDSmWORLDHAND"; //17  //These should be changed for each implementation
        //The length of the strings should be maintained
        public static string rsaKey = "BILLIONbbZZZfeultgbskdmArtichoke"; //32

        public static string EncryptString(string ClearText)
        {
            try
            {
                byte[] clearTextBytes = Encoding.UTF8.GetBytes(ClearText);
                System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
                MemoryStream ms = new MemoryStream();
                byte[] rgbIV = Encoding.ASCII.GetBytes(rsaRgb);
                byte[] key = Encoding.ASCII.GetBytes(rsaKey);
                CryptoStream cs = new CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV), CryptoStreamMode.Write);
                cs.Write(clearTextBytes, 0, clearTextBytes.Length);
                cs.Close();
                return Convert.ToBase64String(ms.ToArray());
            }
            catch
            {
                return "";
            }
        }

        public static string DecryptString(string EncryptedText)
        {
            try
            {
                byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);
                MemoryStream ms = new MemoryStream();
                System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
                byte[] rgbIV = Encoding.ASCII.GetBytes(rsaRgb);
                byte[] key = Encoding.ASCII.GetBytes(rsaKey);
                CryptoStream cs = new CryptoStream(ms, rijn.CreateDecryptor(key, rgbIV),
                CryptoStreamMode.Write);
                cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length);
                cs.Close();
                return Encoding.UTF8.GetString(ms.ToArray());
            }
            catch
            {
                return "";
            }
        }

    }
}

Commits for ChrisCompleteCodeTrunk/ATTP/Action Tire Payment Processor/Encryption.cs

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000