Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 480.6k

encryption key must be the same output

Feb 22 2024 6:59 AM

Hi Team

I need some help, i want my encryption key to be the same as below " wgqpwijwlalgbxbd". Current the propgram only produce this output Enter the encrypted text:
cuanchicken@2024
Encrypted Text VB: WFLskRjyadztIBXvAaUjxNXxpdjSV5DizPrDkRgIWd2qv+dHn76arfENq+mKuOxm
Decrypted Text VB: cuanchicken@2024

 

Imports System.IO
Imports System.Security.Cryptography
Imports System.Text

Namespace Decryption

    Public Module Program
        Public Sub Main()
            Console.WriteLine("Enter the encrypted text:")
            Dim plainText As String = Console.ReadLine()
            Dim encryptedText As String = Encrypt(plainText)
            Console.WriteLine("Encrypted Text VB: " & encryptedText)

            Dim decryptedText As String = Decrypt(encryptedText)
            Console.WriteLine("Decrypted Text VB: " & decryptedText)

            Console.ReadLine()
        End Sub

        Private Function Encrypt(clearText As String) As String
            Dim EncryptionKey As String = "wgqpwijwlalgbxbd"
            Dim clearBytes As Byte() = Encoding.Unicode.GetBytes(clearText)
            Using encryptor As Aes = Aes.Create()
                Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D,
                    &H65, &H64, &H76, &H65, &H64, &H65,
                    &H76})
                encryptor.Key = pdb.GetBytes(32)
                encryptor.IV = pdb.GetBytes(16)
                Using ms As New MemoryStream()
                    Using cs As New CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)
                        cs.Write(clearBytes, 0, clearBytes.Length)
                    End Using
                    Return Convert.ToBase64String(ms.ToArray())
                End Using
            End Using
        End Function

        Private Function Decrypt(cipherText As String) As String
            Dim EncryptionKey As String = "wgqpwijwlalgbxbd"
            Dim cipherBytes As Byte() = Convert.FromBase64String(cipherText)
            Using encryptor As Aes = Aes.Create()
                Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D,
                    &H65, &H64, &H76, &H65, &H64, &H65,
                    &H76})
                encryptor.Key = pdb.GetBytes(32)
                encryptor.IV = pdb.GetBytes(16)
                Using ms As New MemoryStream()
                    Using cs As New CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)
                        cs.Write(cipherBytes, 0, cipherBytes.Length)
                    End Using
                    Return Encoding.Unicode.GetString(ms.ToArray())
                End Using
            End Using
        End Function
    End Module

End Namespace




// c# code console how can i achieve this as well to have same encryption key?

.


Answers (1)