nw.jsでcryptoを使って暗号化されたファイルを復号化しようとした時のこと。下記のようなコードを書いていた。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
try { | |
var decipher = crypto.createDecipher('aes-256-cbc', sfkey); | |
var decrypto = decipher.update(’(暗号化文字列)’, 'hex', 'utf8'); | |
decrypto += decipher.final('utf8'); | |
} catch (e) { | |
console.log(e); | |
} |
そうするとcrypto.createDecipher()
のところで、そんなメソッドはないと怒られる。調べると「crypto」という名前はnw.jsで予約されており、変数名としては使用してはいけないらしい。
Nodejs crypto not working · Issue #540 · nwjs/nw.js · GitHub
nw.jsというよりも、chromiumがcryptoというオブジェクトを持っているためらしい。これは何をするものなのかはわからないが。
Changes related to node · nwjs/nw.js Wiki · GitHub
ということでこの件で小一時間ほどハマってしまった。