Example #1
0
        protected override void Execute(CodeActivityContext context)
        {
            var key       = Key.Get(context);
            var iv        = IV.Get(context);
            var plainText = PlainText.Get(context);

            if (plainText == null || plainText.Length <= 0)
            {
                throw new ArgumentNullException("plainText");
            }
            if (key == null || key.Length <= 0)
            {
                throw new ArgumentNullException("key");
            }

            byte[] encrypted;
            using (AesManaged aes = new AesManaged())
            {
                ICryptoTransform encryptor = aes.CreateEncryptor(Encoding.UTF8.GetBytes(key), Encoding.UTF8.GetBytes(iv));
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter sw = new StreamWriter(cs))
                            sw.Write(plainText);
                        encrypted = ms.ToArray();
                    }
                }
            }

            var result = Convert.ToBase64String(encrypted);

            CipherText.Set(context, result);
        }
Example #2
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var plainText = PlainText.Get(context);

            ///////////////////////////
            // Add execution logic HERE
            string password = "******";
            //Encrypt Text
            string encryptedText = Cipher.Encrypt(plainText, password);

            ///////////////////////////

            // Outputs
            return((ctx) => {
                EncryptedText.Set(ctx, encryptedText);
            });
        }