cancel
Showing results for 
Search instead for 
Did you mean: 

How do i encrypt & decrypt input parameter

AmitChauhan
Level 3
Hi,

I want to encrypt & decrypt input parameter by using AES-256 AesCryptoService scheme, can some one please help me out how do i achieve encryption & decryption in my object or process.

Thanks
Amit

------------------------------
Amit Chauhan
------------------------------
5 REPLIES 5

GopalBhaire
Level 10
You can extend the Utility Encryption VBO to do AES256 encryption.

------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

Thanks!!
I have used Utility Encryption, But utility support DESCryptoService and i have to use AES, 
It would be great help if you can do let me know how do i extend Encryption VBO for AES256 

------------------------------
Amit Chauhan
------------------------------

Refer https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.aes?view=netcore-3.1  you can write something like this. Here I am creating key and then passing it to encrypt 
Action: Generate Key
Output: key, IV and store in Credential Management

Using myAes As Aes = Aes.Create()
	key = Convert.ToBase64String(myAes.Key)
	IV = Convert.ToBase64String(myAes.IV)
End Using
++++++++++++++++++++++++++++++++++++++++++++++++
Action: Encrypt
Input: Key, IV,(from, Credential Management) plaintext 
Output: encrypted

Using aesAlg As Aes = Aes.Create()
        aesAlg.Key = Key
        aesAlg.IV = IV
        Dim encryptor As ICryptoTransform = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV)

        Using msEncrypt As MemoryStream = New MemoryStream()

            Using csEncrypt As CryptoStream = New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)

                Using swEncrypt As StreamWriter = New StreamWriter(csEncrypt)
                    swEncrypt.Write(plainText)
                End Using

                encrypted = msEncrypt.ToArray()
            End Using
        End Using
    End Using

encrypted = Convert.ToBase64String(encrypted)​


------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

Thanks a lot , 
You made my day !!!!

------------------------------
Amit Chauhan
------------------------------

Thanks Gopal  for your help!!

As suggested by you, I have used [(encStream As New CryptoStream(ms, _encStream As New CryptoStream(ms, _ aes.CreateEncryptor(keyb, aes.IV), CryptoStreamMode.Write) Dim sw As New StreamWriter(encStream))] code and AES256 encryption algo  and it is working fine for me. 

Thanks a lot.




------------------------------
Amit Chauhan
------------------------------