コード例 #1
0
        /// <summary>
        /// <see cref="INfieldEncryptionUtility.EncryptText"/>
        /// </summary>
        public EncryptedDataModel EncryptText(string input, string key)
        {
            if (string.IsNullOrEmpty(input))
            {
                throw new ArgumentNullException("input");
            }

            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            var bytesInput = Encoding.UTF8.GetBytes(input);
            var bytesKey   = Convert.FromBase64String(key);

            byte[] iv;

            var result = _aesWrapper.Encrypt(bytesInput, bytesKey, out iv);

            return(new EncryptedDataModel
            {
                Data = Convert.ToBase64String(result),
                InitializationVector = Convert.ToBase64String(iv)
            });
        }