c# - Invalid length for Convert.FromBase64String -
so i'm trying decrypt encrypted string, encrypts fine, , decrypts if i'm lucky enough string length long.. firstly here code called decryption method
decrypted = decrypt(recieved, getstring(anarchyaes.key)); addtochat(decrypted);
recieved encrypted string, , other parameter decryption key. here decrypt method..
public static string decrypt(string cipherstring, string securitykey) { var key = securitykey; var keyarray = encoding.utf8.getbytes(key); var tdes = new tripledescryptoserviceprovider { key = keyarray, mode = ciphermode.ecb, padding = paddingmode.pkcs7 }; var ctransform = tdes.createdecryptor(); var toencryptarray = convert.frombase64string(cipherstring); var resultarray = ctransform.transformfinalblock(toencryptarray, 0, toencryptarray.length); tdes.clear(); return encoding.utf8.getstring(resultarray); }
it fails when does
var toencryptarray = convert.frombase64string(cipherstring);
when string more 7 characters giving error, invalid length 64 base string. i'm wondering how possibly fix this, insight appreciated.
encrpytion code:
public static string encrypt(string toencrypt, string securitykey) { var key = securitykey; var keyarray = encoding.utf8.getbytes(key); var tdes = new tripledescryptoserviceprovider { key = keyarray, mode = ciphermode.ecb, padding = paddingmode.pkcs7 }; var ctransform = tdes.createencryptor(); var toencryptarray = encoding.utf8.getbytes(toencrypt); var resultarray = ctransform.transformfinalblock(toencryptarray, 0, toencryptarray.length); tdes.clear(); return convert.tobase64string(resultarray, 0, resultarray.length); }
Comments
Post a Comment