| HCI超融合登录api密码公钥加密方法--java版 
 1. 首先调用vpai/jaon/public_key获取到公钥信息,这是一个16进制的字符串。
 2.对密码进行加密:
 首选获取公钥
 /**
 * modulus 接口返回的公钥
 * exponent 10001
 */
 public static RSAPublicKey getPublicKey(String modulus, String exponent) {
 try {
 BigInteger b1 = new BigInteger(modulus,16);  //此处为进制数
 BigInteger b2 = new BigInteger(exponent,16);
 KeyFactory keyFactory = KeyFactory.getInstance("RSA");
 RSAPublicKeySpec keySpec = new RSAPublicKeySpec(b1, b2);
 return (RSAPublicKey) keyFactory.generatePublic(keySpec);
 } catch (Exception e) {
 e.printStackTrace();
 return null;
 }
 }
 2. 对密码进行加密
 public static byte[] encrypt(byte[] bt_plaintext, String key)
 throws Exception {
 PublicKey publicKey = getPublicKey(key, exponent);
 
 Cipher cipher = Cipher.getInstance("RSA");
 cipher.init(Cipher.ENCRYPT_MODE, publicKey);
 byte[] bt_encrypted = cipher.doFinal(bt_plaintext);
 return bt_encrypted;
 }
 拿到byte[]结果之后,将这个字节码数组转换为16进制,就完成了对密码的加密。
 
 
 
 |