コード例 #1
0
        protected override void Configure()
        {
            this.CreateMap <CartaoCreditoViewModel, CartaoCredito>()
            .ForMember(x => x.NumeroCriptografado, x => x.ResolveUsing(
                           model => CryptographyAES.Encrypt(model.Numero, model.Senha)
                           ));

            this.CreateMap <CartaoCredito, CartaoCreditoViewModel>()
            .ForMember(x => x.Numero, x => x.ResolveUsing(
                           viewModel => CryptographyAES.Decrypt(viewModel.NumeroCriptografado, viewModel.Senha)
                           ));
        }
コード例 #2
0
        private static void CryptAESTest(Obj obj)
        {
            var crypt = new CryptographyAES(

                key: CryptographyAES.GenerateKey(),
                iv: CryptographyAES.GenerateIV(),
                bits: CryptographyAES.BitsEnum.bit256
                );

            obj.EncryptedWord = crypt.Encrypt(obj.Word);
            obj.DecryptedWord = crypt.Decrypt(obj.EncryptedWord);
        }
        /// <summary>
        /// Encryption algorithm AES
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public dynamic FunctionHandler(Request request, ILambdaContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (request == null || request.Data == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var key  = CryptographyAES.GenerateKey();
            var iv   = CryptographyAES.GenerateIV();
            var bits = CryptographyAES.BitsEnum.bit256;
            var AES  = new CryptographyAES(key, iv, bits);

            var data      = SetTyping(request.Data);
            var encrypted = AES.Encrypt(data);

            context.Logger.Log("Encrypted message.");

            return(new Response(key, iv, (short)bits, encrypted));
        }