云商店
云商店
- 云商店介绍
-
接入指南
-
商品接入相关接口
- SaaS类商品接入指南 V2.0(新商品上架)
- SaaS类商品接入指南 V1.0(已下线)
- 联营License类授权码商品接入指南(2.0版本)
- 联营License类商品接入指南(已下线)
- 自动部署接入指南
- 联营License客户端软件对接指南
- 商品交易相关接口
-
商品接入相关接口
- 用户指南
-
商家指南
- 为什么要加入云商店
- 商家入驻
- 商品发布
- 商品交易
- 商家结算
- 店铺运营
- 政策与权益
- 中资出海
-
商家常见问题
- 商家入驻相关问题
- 联营计划相关问题
-
商品发布相关问题
- 如何在云商店发布商品
- 如何发布多SKU定价规格
- 商品发布申请提交后,审核需要多久
- 如何判断发布的商品对应云商店上的哪种商品接入类型
- 云商店商品上架的使用有效期
- 新商品发布时,“商品说明”中能否插入图片
- 为什么在商品发布页面没有发布联营商品按钮
- 如何创建SaaS按需规格和按需套餐包
- 如何补充商品交付模板
- 商品名称发布说明
- 商品logo、商品主图与视频、商品简介、商品说明发布说明
- 联营商品服务支持条款发布说明
- 通用商品服务协议发布说明
- 服务与支持、使用指南发布说明
- 软件著作权证书发布说明
- 通用商品规格发布说明
- 联营商品规格对照报价单填写说明
- 联营服务流发布说明
- 生产接口地址、安全漏洞扫描、关联应用发布说明
- 如何发布SaaS类商品试用规格
- 云商店镜像资产无法选择到已创建私人镜像的原因
- 商品管理相关问题
- 服务监管相关问题
- 结算相关问题
- 协议与规范
- 客户服务商指南
- 平台规范与通知
- 文档下载
- 通用参考
本文导读
展开导读
文档首页/
云商店/
接入指南/
商品接入相关接口/
SaaS类商品接入指南 V1.0(已下线)/
通用和自服务SaaS类商品接入指南 V1.0/
代码示例(Java)/
ISV Server对资源开通后的用户名和密码加密
链接复制成功!
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; }
父主题: 代码示例(Java)