Argentini.Halide.H3Secure.EncryptInt32 C# (CSharp) Method

EncryptInt32() public static method

Triple DES 256 bit encryption of 32-bit integers.
public static EncryptInt32 ( Int32 data, Byte key, Byte ivec ) : String
data System.Int32 Integer to encrypt.
key Byte 24 byte array key for encrypting the data.
ivec Byte 18 byte array initialization vector for the encryption routine.
return String
        public static String EncryptInt32(Int32 data, Byte[] key, Byte[] ivec)
        {
            String retVal = "";

            try
            {
                ASCIIEncoding encoder = new ASCIIEncoding();

                Byte[] inputInBytes = BitConverter.GetBytes(data);

                AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
                aesProvider.BlockSize = 128;
                aesProvider.KeySize = 256;
                ICryptoTransform cryptoTransform = aesProvider.CreateEncryptor(key, ivec);
                MemoryStream encryptedStream = new MemoryStream();
                CryptoStream cryptStream = new CryptoStream(encryptedStream, cryptoTransform, CryptoStreamMode.Write);

                cryptStream.Write(inputInBytes, 0, inputInBytes.Length);
                cryptStream.FlushFinalBlock();
                encryptedStream.Position = 0;

                Byte[] result = new byte[encryptedStream.Length];
                encryptedStream.Read(result, 0, Convert.ToInt32(encryptedStream.Length));

                cryptStream.Close();

                retVal = Base64PlusStringEncode(result);
            }

            catch (Exception err)
            {
                throw new Exception("Halide.H3Secure Error: " + err.ToString());
            }

            return retVal;
        }

Same methods

H3Secure::EncryptInt32 ( Int32 data ) : String
H3Secure::EncryptInt32 ( Int32 data, Byte key ) : String
H3Secure::EncryptInt32 ( Int32 data, String key, String ivec ) : String