c# - Blowfish CBC encryption not decrypting -
i have difficulties decrypting blowfish encrypted string in .net environment, encrypted mcrypt php library.
here script use encrypt data
<?php function encrypt_blowfish($data, $key) { $iv_size = mcrypt_get_iv_size(mcrypt_blowfish, mcrypt_mode_cbc); $iv = mcrypt_create_iv($iv_size, mcrypt_rand); $crypttext = mcrypt_encrypt(mcrypt_blowfish, $key, $data, mcrypt_mode_cbc, $iv); echo 'iv: ' . bin2hex($iv) . "\n"; echo 'data: ' . bin2hex($crypttext) ."\n" ; } $secretkey = 'somekey'; $data = 'hello world encryptiontest!'; encrypt_blowfish($data, $secretkey); i decided use bouncingcastle library since seemed default choice encryption , had pcl version (which need). testing purpose copy/pasted echo'd values c# code.
var ivstring = "34c33fed0386dda1"; var iv = hex.decode (ivstring); var datastring = "ced4ed218d7a1fd228f8c43ca6b83f097648811661d5510678a26953729ceccdf6d78a7695cbfe43"; var data = hex.decode (datastring); var keystring = "somekey"; var key = system.text.encoding.utf8.getbytes (keystring); var engine = new blowfishengine(); var cipher =new paddedbufferedblockcipher(new cbcblockcipher(engine)); var keyparam = new keyparameter(key); cipher.init (false, keyparam); var outbytes = new byte[data.length]; var len = cipher.processbytes (data, 0, data.length, outbytes, 0); cipher.dofinal(outbytes, len); console.writeline(system.text.encoding.utf8.getstring(outbytes)); when run code dofinal explodes "corrupt padding block" exception. read pcks7 padding fills bytes of original string. calculated input string , blowfish cbc algorithm block size of 8, need 2 bytes of padding added "22" @ end of string. yielded same result.
also, don't see point can insert iv blowfish decryption. feels lacking/not understanding vital point here. any1 ideas on goes wrong here? if possible skip on padding part in php , decrypt iv/passphrase in c#, possible?
cheers , thanks
tom
i ended using simpler library supperts cbc mode in simple fashion.
http://jaryl-lan.blogspot.de/2014/07/openfire-blowfish-encryptiondecryption.html
Comments
Post a Comment