Exemplo n.º 1
0
        public string EncryptText(string input, byte[] passcode)
        {
            if (String.IsNullOrWhiteSpace(input))
            {
                return(String.Empty);
            }

            try
            {
                byte[] bytesToBeEncrypted = Encoding.UTF8.GetBytes(input);

                AesCryptography aesCryptor     = new AesCryptography();
                byte[]          encryptedBytes = aesCryptor.EncryptBytes(bytesToBeEncrypted, passcode);
                string          output         = Convert.ToBase64String(encryptedBytes);
                return(output);
            }
            catch (ZXEncryptionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ZXEncryptionException("Encryption error occurred.", ex);
            }
        }
Exemplo n.º 2
0
        public byte[] EncryptBytes(byte[] bytesToBeEncrypted, byte[] passcode)
        {
            if (bytesToBeEncrypted == null || bytesToBeEncrypted.Length == 0)
            {
                return(null);
            }

            try
            {
                AesCryptography aesCryptor     = new AesCryptography();
                byte[]          encryptedBytes = aesCryptor.EncryptBytes(bytesToBeEncrypted, passcode);
                return(encryptedBytes);
            }
            catch (Exception ex)
            {
                throw new ZXEncryptionException("Encryption error occurred.", ex);
            }
        }