- 云商店介绍
-
商家指南
- 商家入驻
- 商品发布
- 商品交易
- 商家结算
- 店铺运营
- 政策与权益
-
商家常见问题
- 入驻前需要准备哪些企业证件
- 商家退出后,是否还能申请入驻
- 如何加入云商店合作伙伴
- 提交入驻申请后,审核需要多久
- 如何在云商店发布产品
- 商品发布申请提交后,审核需要多久
- 商品如何下架
- 订单出账后,什么时间能收到回款
- 如何判断订单是否符合开票条件?我的订单是否可开具发票?我可以开票了吗?
- 产品技术支持是卖家还是华为云提供
- 云商店商品上架的使用有效期
- 如何发起服务监管申诉
- 个人是否能成为云商店的seller
- 入驻云商店可以享受哪些利好
- 入驻云商店收取保证金吗
- 如何修改公司名称
- 订单为什么没出账?出账的前提是什么?
- 如何查看商品的分成比例
- 如何发布SaaS类商品试用规格
- 云商店镜像资产无法选择到已创建私人镜像的原因
- 经销商指南
- 用户指南
- 接入指南
- 通用参考
展开导读
链接复制成功!
ISV Server对资源开通后的用户名和密码加密
代码调用如下图所示。
/** * 对资源开通后,返回的用户名和密码进行加密 * @param key 秘钥 * @param str 原文 * @param encryptLength 加密长度 * @return 加密结果 */ public static String generateSaaSUsernameOrPwd(String key, String str, int encryptLength) { String iv = getRandomChars(16); String afterEncryptStr = ""; try { afterEncryptStr = encryptAESCBCEncode(str, key, iv, encryptLength); } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) { //TODO:异常处理 } System.out .println(afterEncryptStr); return iv + afterEncryptStr; } |
/** * 随机生成字符串 * @param length 随机字符串的长度 * @return 随机字符串 */ public static String getRandomChars(int length) { String randomChars = ""; SecureRandom random = new SecureRandom(); for (int i = 0; i < length; i++) { //字母和数字中随机 if (random.nextInt(2) % 2 == 0) { //输出是大写字母还是小写字母 int letterIndex = random.nextInt(2) % 2 == 0 ? 65 : 97; randomChars += (char) (random.nextInt(26) + letterIndex); } else { randomChars += String.valueOf(random.nextInt(10)); } } return randomChars; } |
/** * AES CBC 加密 * @param content 加密内容 * @param key 加密秘钥 * @param iv 向量iv * @param encryptLength 仅支持128、256长度 * @return 加密结果 * @throws BadPaddingException * @throws IllegalBlockSizeException * @throws InvalidAlgorithmParameterException * @throws NoSuchPaddingException * @throws NoSuchAlgorithmException * @throws InvalidKeyException */ public static String encryptAESCBCEncode(String content, String key, String iv, int encryptLength) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { if (StringUtils.isEmpty(content) || StringUtils.isEmpty(key) || StringUtils.isEmpty(iv)) { return null; } return base_64( encryptAESCBC(content.getBytes(), key.getBytes(), iv.getBytes(), encryptLength)); } |
/** * * AES CBC 256位加密 * @param content 加密内容字节数组 * @param keyBytes 加密字节数组 * @param iv 加密向量字节数组 * @param encryptLength 仅支持128、256长度 * @return 解密后字节内容 * @throws NoSuchAlgorithmException * @throws NoSuchPaddingException * @throws InvalidKeyException * @throws InvalidAlgorithmParameterException * @throws IllegalBlockSizeException * @throws BadPaddingException */ public static byte[] encryptAESCBC(byte[] content, byte[] keyBytes, byte[] iv, int encryptLength) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG"); secureRandom.setSeed(keyBytes); keyGenerator.init(encryptLength, secureRandom); SecretKey key = keyGenerator.generateKey(); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv)); byte[] result = cipher.doFinal(content); return result; } |