Exemple #1
0
        internal int KeyEncryption(int msg, string enckey)
        {
            try
            {
                byte[] plain, enc, iv;
                plain = IntToBytes(msg);
                iv    = GetRandomBytes(16);

                if (AES == null)
                {
                    AES = new AEScustom();
                }

                AES.Key     = Hex2Bytes(enckey);
                AES.Mode    = CipherMode.CBC;
                AES.Padding = PaddingMode.PKCS7;
                AES.IV      = iv;
                enc         = AES.Encrypt(plain);
                KeyBc       = ToHexInt(ref iv, 0, 16, string.Empty) + ToHexInt(ref enc, 0, enc.Length, string.Empty);
                return(KeyBc);
            }
            catch (Exception e) when(e is Exception || e is CryptographicUnexpectedOperationException)
            {
                return(0);
            }
        }
Exemple #2
0
        internal Encryption(string msg, string enckey)
        {
            string s = string.Empty;

            try
            {
                AES = new AEScustom();
                byte[] plain, enc, iv;
                plain = StringToBytes(ref msg);
                iv    = GetRandomBytes(16);
                if (AES == null)
                {
                    return;
                }
                AES.Key     = Hex2Bytes(enckey);
                AES.Mode    = CipherMode.CBC;
                AES.Padding = PaddingMode.PKCS7;
                AES.IV      = iv;
                enc         = AES.Encrypt(plain);
            }
            catch (Exception e) when(e is Exception || e is CryptographicUnexpectedOperationException)
            {
                success   = false;
                exception = e.Message;
                return;
            }
        }