将密码过程从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) throws NoSuchAlgorithmException { SecretKeySpec skeySpec = null; Provider sunJce = new SunJCE(); Security.addProvider(sunJce); KeyGenerator kgen = KeyGenerator.getInstance("Blowfish"); kgen.init(448); byte[] raw = key.getBytes(); skeySpec = new SecretKeySpec(raw, "Blowfish"); return skeySpec; } 

由于我们一直在冲浪,并没有find任何相关的Appart包“crypto”节点,看起来不错,但我们不知道用什么方法来模拟预期的结果。

如果还有其他事情可以帮助你理解我们的问题,请告诉我。

谢谢你的时间。