vb.net - How to encrypt and decrypt string to base64? -


good day all, new vb.net programming. wanted encrypt , decrypt user passwords, came code below.

 imports system.security.cryptography  imports system.text   public class updatepass     dim des new tripledescryptoserviceprovider    dim md5 new md5cryptoserviceprovider   function encrypt(stringinput string, key string) string     des.key = md5hash(key)     des.mode = ciphermode.ecb     dim buffer byte() = asciiencoding.ascii.getbytes(stringinput)     return convert.tobase64string(des.createencryptor().transformfinalblock(buffer, 0, buffer.length)) end function   function decrypt(encryptedstring string, key string) string     des.key = md5hash(key)     des.mode = ciphermode.ecb     dim buffer byte() = convert.frombase64string(encryptedstring)     return asciiencoding.ascii.getstring(des.createdecryptor().transformfinalblock(buffer, 0, buffer.length)) end function  function md5hash(value string) byte()     return md5.computehash(asciiencoding.ascii.getbytes(value)) end function  end class 

when execute code , decrypt, error message.

an unhandled exception of type 'system.security.cryptography.cryptographicexception' occurred in mscorlib.dll additional information: length of data decrypt invalid.

i hope can me this. thank you!

your code works fine me. check if key entering encryption same decryption


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -