{"issue":{"created_at":"2011-11-03T05:11:49Z","state":"closed","updated_at":"2011-11-30T01:24:43Z","comments":8,"user":{"gravatar_id":"8ad55a911ada4e6df24cc1bc4c57ef16","id":438358,"url":"https://api.github.com/users/KiNgMaR","avatar_url":"https://secure.gravatar.com/avatar/8ad55a911ada4e6df24cc1bc4c57ef16?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"KiNgMaR"},"body":"Hey there.\r\nI was trying to decrypt some Blowfish-ECB-mode encrypted strings with node.js, but all I got was weird characters. After making an isolated test case, I discovered that node.js is not using OpenSSL's EVP_CIPHER_CTX_set_key_length correctly.\r\n\r\nIt's called *after* EVP_CipherInit, so it will just silently do nothing (won't return any error code either). However, unless you're using a cipher with a variable key length (such as Blowfish ECB) it will go unnoticed. The fix is to use EVP_CipherInit_ex instead and to call it two times, as (dimly) described by EVP_CipherInit_ex's man page on openssl.org[1].\r\n\r\nSo here's a pull request and a test case.\r\n\r\nI have also changed the code to use EVP_EncryptFinal_ex to go along with the _ex init call which should not have any side effects since at least in current OpenSSLs (haven't checked 0.x ones), Final is simply an alias to Final_ex.\r\n\r\nAlso here's a standalone cpp file I used for testing: https://gist.github.com/1335823 BF_ecb_encrypt is used to verify the output.\r\n\r\nLooking forward to reading your comments.\r\n\r\n[1] http://www.openssl.org/docs/crypto/EVP_EncryptInit.html","assignee":null,"id":2129456,"labels":[{"name":"crypto","color":"e10c02","url":"https://api.github.com/repos/joyent/node/labels/crypto"}],"pull_request":{"patch_url":"https://github.com/joyent/node/pull/1997.patch","html_url":"https://github.com/joyent/node/pull/1997","diff_url":"https://github.com/joyent/node/pull/1997.diff"},"number":1997,"title":"OpenSSL EVP API Fix (ECB mode failing)","closed_at":"2011-11-30T01:24:43Z","html_url":"https://github.com/joyent/node/issues/1997","url":"https://api.github.com/repos/joyent/node/issues/1997","milestone":null},"action":"created","comment":{"created_at":"2011-11-30T01:24:43Z","updated_at":"2011-11-30T01:24:43Z","user":{"gravatar_id":"3d43d9038ab645ecb2e3a1df2951d30a","id":275871,"url":"https://api.github.com/users/bnoordhuis","avatar_url":"https://secure.gravatar.com/avatar/3d43d9038ab645ecb2e3a1df2951d30a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"bnoordhuis"},"body":"Thanks Ingmar, merged in 2603832.","id":2953547,"url":"https://api.github.com/repos/joyent/node/issues/comments/2953547"}}