本人新手,现遇到个项目,需要进行"RSA/ECB/PKCS1Padding"算法加密. java代码如下: public static String encrypt(String source, String publicKey) throws Exception { Key key = getPublicKey(publicKey); /** 得到Cipher对象来实现对源数据的RSA加密 / Cipher cipher = Cipher.getInstance(“RSA/ECB/PKCS1Padding”); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] b = source.getBytes(); /* 执行加密操作 */ byte[] b1 = cipher.doFinal(b); return new String(Base64.encodeBase64(b1), UTF-8); } public static PublicKey getPublicKey(String key) throws Exception { X509EncodedKeySpec keySpec = new X509EncodedKeySpec( Base64.decodeBase64(key.getBytes())); KeyFactory keyFactory = KeyFactory.getInstance(“RSA”); PublicKey publicKey = keyFactory.generatePublic(keySpec); return publicKey; } 我该如何将java代码转为为node.js,运用Cipher加密,应该调哪个模块,求告知。
作者
作者其它话题
无