{"action":"created","issue":{"url":"https://api.github.com/repos/iojs/io.js/issues/1270","labels_url":"https://api.github.com/repos/iojs/io.js/issues/1270/labels{/name}","comments_url":"https://api.github.com/repos/iojs/io.js/issues/1270/comments","events_url":"https://api.github.com/repos/iojs/io.js/issues/1270/events","html_url":"https://github.com/iojs/io.js/issues/1270","id":64547460,"number":1270,"title":"Unable to decrypt aes-256-cbc created by PHP ","user":{"login":"abrkn","id":843958,"avatar_url":"https://avatars.githubusercontent.com/u/843958?v=3","gravatar_id":"","url":"https://api.github.com/users/abrkn","html_url":"https://github.com/abrkn","followers_url":"https://api.github.com/users/abrkn/followers","following_url":"https://api.github.com/users/abrkn/following{/other_user}","gists_url":"https://api.github.com/users/abrkn/gists{/gist_id}","starred_url":"https://api.github.com/users/abrkn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abrkn/subscriptions","organizations_url":"https://api.github.com/users/abrkn/orgs","repos_url":"https://api.github.com/users/abrkn/repos","events_url":"https://api.github.com/users/abrkn/events{/privacy}","received_events_url":"https://api.github.com/users/abrkn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-26T14:58:11Z","updated_at":"2015-03-26T15:21:52Z","closed_at":null,"body":"I'm trying to decrypt some data that was encrypted by PHP and can be decrypted by PHP:\r\n\r\n```\r\n<?php\r\n// aes-256-cbc.php\r\n\r\n$emsg = hex2bin('ad0911ac3c5b95a70c7109b025a8947ff1adb882101b2ec137f35919f41a49c9314d27c7f376c5e013a44f91f4d30fbba3f27834e8a200ea494debc90a9dca5cd8cbedea4168719feee05b7c65adf3f226eefb6f851eddb1f10c4ef3c007ea7e683d4ed6e0139520d8df0830b8a0de5b18acf7d6531cdb43d0310095f70d72adee8717cf29230be4ba654ac985d5d1460d43d6c35da39787051b902d6278f95049b0a12b7d413ee28c8b353fcd2b0603abee9eda15ee795bfaa0807b46730b2f2ccb6193771bc10c79ba088aaf04bde255a6bbd462ec4db289a6d2d8e3b18214dbe69f212513274c5045e823b8c1f1e7aba39929eb3d2028e0259d5804470191d10e5cfa608faa7b82e0092f1d22ff31af7f4e9aac6edbaa5bb6c5b612c1a45f30e918ad48c989e02e80c74fbe336d630e33d3dca75b45b9d8924997a604b905d87058aae125bc4bb2d5632d0ad80ffcb4c478ac89bb790516bce81cfc03d731e2c0f36f4e42e6525456f35630e753d3be0dd70efdfe23657c912b34566499d555fc6c3e7410deed78eb73a06b46066f35d3ed19e1f79529b5ab578b2cb58e255a50c1e1842bed7c4e7c038388c1cc0bb4806b45c13b1a641cfcb0062ef9c2102498d9524de8647e402b3ac977d4bc232ff2720d51d9ca77cb9d7dc2c51f0e0bd6054d0904f7d22e5a5d0b653485765bc24b79a590bd2a2fbb5f2bac7b52cde1019b16db72b1df579f4728980f4d774000a6c5fa90e5b3fe798c7e4124a7e530451ce1177b752f55ead962886ff2cd7095f97f1f206a15575e026f00f8ca63adfd12d609a10b23e61ba4889f5af007ed8b7c9fee1e0cae86a59ad5599fddaeb233b4f7b946b790524aad4423d1979ac2552e301d7645d1f2b437908ed36d1fcb1379cfd703fcce4a51a1ae913c5e05e2e28d55a312bec1972be50ad03de5cadd');\r\n$key = hex2bin('506b5313333df5034b090a1d640163e7ab17cd86f43bdd6117caff7777f094b9');\r\n$iv = hex2bin('699b25b0906cb81a08e53ba047c1b2b4');\r\n$msg = openssl_decrypt($emsg, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);\r\n$msg = substr($msg, 2);\r\necho \"$msg\\n\";\r\n\r\n/*\r\n\r\n$ php -f aes-256-cbc.php\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Duis fringilla nunc nisi, ac elementum sem mollis non. Pellentesque rhoncus odio a sapien mattis, consequat varius diam mattis. Aliquam maximus nunc et velit accumsan imperdiet. Phasellus nec tristique quam. Integer felis ipsum, accumsan quis ex eget, aliquam pulvinar ipsum. Vestibulum accumsan faucibus porttitor. Phasellus varius metus at semper pretium. Praesent tristique nec libero id aliquam. Proin ultrices, diam ut commodo placerat, risus lectus faucibus nisi, id efficitur arcu dolor id felis. Phasellus eleifend vitae nisi in ullamcorper. Duis luctus nisi non risus tristique, et aliquam leo auctor.\r\n\r\n*/\r\n```\r\n\r\nio.js code:\r\n\r\n```\r\n// aes-256-cbc.js\r\nvar crypto = require('crypto');\r\n\r\nvar emsg = new Buffer('ad0911ac3c5b95a70c7109b025a8947ff1adb882101b2ec137f35919f41a49c9314d27c7f376c5e013a44f91f4d30fbba3f27834e8a200ea494debc90a9dca5cd8cbedea4168719feee05b7c65adf3f226eefb6f851eddb1f10c4ef3c007ea7e683d4ed6e0139520d8df0830b8a0de5b18acf7d6531cdb43d0310095f70d72adee8717cf29230be4ba654ac985d5d1460d43d6c35da39787051b902d6278f95049b0a12b7d413ee28c8b353fcd2b0603abee9eda15ee795bfaa0807b46730b2f2ccb6193771bc10c79ba088aaf04bde255a6bbd462ec4db289a6d2d8e3b18214dbe69f212513274c5045e823b8c1f1e7aba39929eb3d2028e0259d5804470191d10e5cfa608faa7b82e0092f1d22ff31af7f4e9aac6edbaa5bb6c5b612c1a45f30e918ad48c989e02e80c74fbe336d630e33d3dca75b45b9d8924997a604b905d87058aae125bc4bb2d5632d0ad80ffcb4c478ac89bb790516bce81cfc03d731e2c0f36f4e42e6525456f35630e753d3be0dd70efdfe23657c912b34566499d555fc6c3e7410deed78eb73a06b46066f35d3ed19e1f79529b5ab578b2cb58e255a50c1e1842bed7c4e7c038388c1cc0bb4806b45c13b1a641cfcb0062ef9c2102498d9524de8647e402b3ac977d4bc232ff2720d51d9ca77cb9d7dc2c51f0e0bd6054d0904f7d22e5a5d0b653485765bc24b79a590bd2a2fbb5f2bac7b52cde1019b16db72b1df579f4728980f4d774000a6c5fa90e5b3fe798c7e4124a7e530451ce1177b752f55ead962886ff2cd7095f97f1f206a15575e026f00f8ca63adfd12d609a10b23e61ba4889f5af007ed8b7c9fee1e0cae86a59ad5599fddaeb233b4f7b946b790524aad4423d1979ac2552e301d7645d1f2b437908ed36d1fcb1379cfd703fcce4a51a1ae913c5e05e2e28d55a312bec1972be50ad03de5cadd', 'hex');\r\nvar key = new Buffer('506b5313333df5034b090a1d640163e7ab17cd86f43bdd6117caff7777f094b9', 'hex');\r\nvar iv = new Buffer('699b25b0906cb81a08e53ba047c1b2b4', 'hex');\r\n\r\nvar decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);\r\ndecipher.update(emsg);\r\n\r\nvar msg = decipher.final();\r\nmsg = msg.slice(2);\r\nconsole.log(msg.toString('utf8'));\r\n\r\n/*\r\n$ node temp/aes-256-cbc.js\r\nleo auctor.\r\n*/\r\n```\r\n\r\nMy versions:\r\n\r\n```\r\n$ openssl version\r\nOpenSSL 1.0.2 22 Jan 2015\r\n$ php --version\r\nPHP 5.4.38 (cli) (built: Feb 26 2015 09:21:22)\r\nCopyright (c) 1997-2014 The PHP Group\r\nZend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies\r\n$ node --version\r\nv1.3.0\r\n$ system_profiler SPSoftwareDataType\r\nSoftware:\r\n\r\n    System Software Overview:\r\n\r\n      System Version: OS X 10.10.2 (14C1514)\r\n      Kernel Version: Darwin 14.1.0\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/iojs/io.js/issues/comments/86566457","html_url":"https://github.com/iojs/io.js/issues/1270#issuecomment-86566457","issue_url":"https://api.github.com/repos/iojs/io.js/issues/1270","id":86566457,"user":{"login":"mscdex","id":54666,"avatar_url":"https://avatars.githubusercontent.com/u/54666?v=3","gravatar_id":"","url":"https://api.github.com/users/mscdex","html_url":"https://github.com/mscdex","followers_url":"https://api.github.com/users/mscdex/followers","following_url":"https://api.github.com/users/mscdex/following{/other_user}","gists_url":"https://api.github.com/users/mscdex/gists{/gist_id}","starred_url":"https://api.github.com/users/mscdex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mscdex/subscriptions","organizations_url":"https://api.github.com/users/mscdex/orgs","repos_url":"https://api.github.com/users/mscdex/repos","events_url":"https://api.github.com/users/mscdex/events{/privacy}","received_events_url":"https://api.github.com/users/mscdex/received_events","type":"User","site_admin":false},"created_at":"2015-03-26T15:21:52Z","updated_at":"2015-03-26T15:21:52Z","body":"You're discarding the initially decrypted contents by not doing anything with the result from [`decipher.update()`](https://iojs.org/api/crypto.html#crypto_decipher_update_data_input_encoding_output_encoding).\r\n\r\nThis example will work as expected:\r\n\r\n```javascript\r\nvar crypto = require('crypto');\r\n\r\nvar emsg = new Buffer('ad0911ac3c5b95a70c7109b025a8947ff1adb882101b2ec137f35919f41a49c9314d27c7f376c5e013a44f91f4d30fbba3f27834e8a200ea494debc90a9dca5cd8cbedea4168719feee05b7c65adf3f226eefb6f851eddb1f10c4ef3c007ea7e683d4ed6e0139520d8df0830b8a0de5b18acf7d6531cdb43d0310095f70d72adee8717cf29230be4ba654ac985d5d1460d43d6c35da39787051b902d6278f95049b0a12b7d413ee28c8b353fcd2b0603abee9eda15ee795bfaa0807b46730b2f2ccb6193771bc10c79ba088aaf04bde255a6bbd462ec4db289a6d2d8e3b18214dbe69f212513274c5045e823b8c1f1e7aba39929eb3d2028e0259d5804470191d10e5cfa608faa7b82e0092f1d22ff31af7f4e9aac6edbaa5bb6c5b612c1a45f30e918ad48c989e02e80c74fbe336d630e33d3dca75b45b9d8924997a604b905d87058aae125bc4bb2d5632d0ad80ffcb4c478ac89bb790516bce81cfc03d731e2c0f36f4e42e6525456f35630e753d3be0dd70efdfe23657c912b34566499d555fc6c3e7410deed78eb73a06b46066f35d3ed19e1f79529b5ab578b2cb58e255a50c1e1842bed7c4e7c038388c1cc0bb4806b45c13b1a641cfcb0062ef9c2102498d9524de8647e402b3ac977d4bc232ff2720d51d9ca77cb9d7dc2c51f0e0bd6054d0904f7d22e5a5d0b653485765bc24b79a590bd2a2fbb5f2bac7b52cde1019b16db72b1df579f4728980f4d774000a6c5fa90e5b3fe798c7e4124a7e530451ce1177b752f55ead962886ff2cd7095f97f1f206a15575e026f00f8ca63adfd12d609a10b23e61ba4889f5af007ed8b7c9fee1e0cae86a59ad5599fddaeb233b4f7b946b790524aad4423d1979ac2552e301d7645d1f2b437908ed36d1fcb1379cfd703fcce4a51a1ae913c5e05e2e28d55a312bec1972be50ad03de5cadd', 'hex');\r\nvar key = new Buffer('506b5313333df5034b090a1d640163e7ab17cd86f43bdd6117caff7777f094b9', 'hex');\r\nvar iv = new Buffer('699b25b0906cb81a08e53ba047c1b2b4', 'hex');\r\n\r\nvar decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);\r\n\r\nvar msg = Buffer.concat([decipher.update(emsg), decipher.final()]);\r\nmsg = msg.slice(2);\r\nconsole.log(msg.toString('utf8'));\r\n```"}}