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
Post a Comment