Tag: blowfish

将密码过程从java转换为nodejs(Blowfish)

我们正在将一个用java编写的旧中间件迁移到我们的服务器上,我们想把它写在nodejs中,我们不知道如何翻译一些函数: 有了第一个函数,我们需要在nodejs中find一个Cipher类的解决scheme,我们还没有find解决scheme,是否有任何“simmetric”或类似的包,我们可以在节点中使用? public static String encryptBlowFish(String cleartext, String key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException { String encBlowFish = ""; SecretKeySpec skeySpec = getGenerateKey(key); Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); cipher.init(1, skeySpec); byte[] raw = cipher.doFinal(cleartext.getBytes("UTF8")); encBlowFish = new Base64Encoder().encode(raw); encBlowFish = URLEncoder.encode(encBlowFish, "UTF8"); encBlowFish = specialChars(encBlowFish); return encBlowFish; } 对于第二种方法,它几乎是相同的,我们需要在节点中的解决scheme来模拟此行为: private static SecretKeySpec getGenerateKey(String key) […]

使用node.js解密mcrypt编码的文本

我使用PHP的mcrypt编码了Blowfish的文本: $td = mcrypt_module_open ('blowfish', '', 'cfb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); mcrypt_generic_init ($td, "somekey", $iv); $crypttext = mcrypt_generic ($td, "sometext"); mcrypt_generic_deinit ($td); $res = base64_encode($iv.$crypttext); 当试图用Node的encryption库解码数据时,我得到垃圾输出。 var crypto = require("crypto"), ivAndCiphertext = "base64-encoded-ciphertext", iv, cipherText, ivSize = 8, res= ""; ivAndCiphertext = new Buffer(ivAndCiphertext, 'base64'); iv = new Buffer(ivSize); cipherText = new […]