AppKey:可以认为是你申请的应用的一个唯一标识
 AppSecret:你申请的应用的密钥,主要用于对请求参数签名,和对回调参数验证。

 生成后的效果

private final static String[] chars = new String[]{"a", "b", "c", "d", "e", "f","g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s","t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5","6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I","J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V","W", "X", "Y", "Z"};//生成8位appKey
public static String getAppKey() {StringBuffer shortBuffer = new StringBuffer();//获取用户id进行字符串截取String uuid = UUID.randomUUID().toString().replace("-", "");for (int i = 0; i < 8; i++) {String str = uuid.substring(i * 4, i * 4 + 4);int x = Integer.parseInt(str, 16);shortBuffer.append(chars[x % 0x3E]);}return shortBuffer.toString();}//生成32位appSecret
public static String getAppSecret(String appId){String EncryoAppSecret="";try {EncrypDES des1 = new EncrypDES();// 使用默认密钥EncryoAppSecret=des1.encrypt(appId);} catch (Exception e) {e.printStackTrace();}return EncryoAppSecret;
}

 如何使用

SmsType smsType =new SmsType();//实例化实体
String appKey = getAppKey();  //定义变量接收
String appSecret = getAppSecret(appKey);
smsType.setAppKey(appKey);   //实体赋值
smsType.setAppSecret(appSecret);

 EncrypDES工具类

/*** @program: nutzsite* @description: 加密解密字符串的方法**/
package io.nutz.nutzsite.common.utils;import java.security.Key;
import javax.crypto.Cipher;public class EncrypDES {// 字符串默认键值private static String strDefaultKey = "inventec2020@#$%^&";//加密工具private Cipher encryptCipher = null;// 解密工具private Cipher decryptCipher = null;/*** 默认构造方法,使用默认密钥*/public EncrypDES() throws Exception {this(strDefaultKey);}/*** 指定密钥构造方法* @param strKey 指定的密钥* @throws Exception*/public EncrypDES(String strKey) throws Exception {// Security.addProvider(new com.sun.crypto.provider.SunJCE());Key key = getKey(strKey.getBytes());encryptCipher = Cipher.getInstance("DES");encryptCipher.init(Cipher.ENCRYPT_MODE, key);decryptCipher = Cipher.getInstance("DES");decryptCipher.init(Cipher.DECRYPT_MODE, key);}/*** 将byte数组转换为表示16进制值的字符串, 如:byte[]{8,18}转换为:0813,和public static byte[]** hexStr2ByteArr(String strIn) 互为可逆的转换过程** @param arrB 需要转换的byte数组* @return 转换后的字符串* @throws Exception  本方法不处理任何异常,所有异常全部抛出*/public static String byteArr2HexStr(byte[] arrB) throws Exception {int iLen = arrB.length;// 每个byte用2个字符才能表示,所以字符串的长度是数组长度的2倍StringBuffer sb = new StringBuffer(iLen * 2);for (int i = 0; i < iLen; i++) {int intTmp = arrB[i];// 把负数转换为正数while (intTmp < 0) {intTmp = intTmp + 256;}// 小于0F的数需要在前面补0if (intTmp < 16) {sb.append("0");}sb.append(Integer.toString(intTmp, 16));}return sb.toString();}/*** 将表示16进制值的字符串转换为byte数组,和public static String byteArr2HexStr(byte[] arrB)* 互为可逆的转换过程* @param strIn 需要转换的字符串* @return 转换后的byte数组*/public static byte[] hexStr2ByteArr(String strIn) throws Exception {byte[] arrB = strIn.getBytes();int iLen = arrB.length;// 两个字符表示一个字节,所以字节数组长度是字符串长度除以2byte[] arrOut = new byte[iLen / 2];for (int i = 0; i < iLen; i = i + 2) {String strTmp = new String(arrB, i, 2);arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16);}return arrOut;}/**** 加密字节数组* @param arrB 需加密的字节数组* @return 加密后的字节数组*/public byte[] encrypt(byte[] arrB) throws Exception {return encryptCipher.doFinal(arrB);}/*** 加密字符串* @param strIn 需加密的字符串* @return 加密后的字符串*/public String encrypt(String strIn) throws Exception {return byteArr2HexStr(encrypt(strIn.getBytes()));}/*** 解密字节数组* @param arrB 需解密的字节数组* @return 解密后的字节数组*/public byte[] decrypt(byte[] arrB) throws Exception {return decryptCipher.doFinal(arrB);}/*** 解密字符串* @param strIn 需解密的字符串* @return 解密后的字符串*/public String decrypt(String strIn) throws Exception {return new String(decrypt(hexStr2ByteArr(strIn)));}/*** 从指定字符串生成密钥,密钥所需的字节数组长度为8位 不足8位时后面补0,超出8位只取前8位* @param arrBTmp 构成该字符串的字节数组* @return 生成的密钥*/private Key getKey(byte[] arrBTmp) throws Exception {// 创建一个空的8位字节数组(默认值为0)byte[] arrB = new byte[8];// 将原始字节数组转换为8位for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {arrB[i] = arrBTmp[i];}// 生成密钥Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");return key;}public static void main(String[] args) throws Exception {String code="427d68ae59e577f7b87f05d43670df58";EncrypDES encrypDES=new EncrypDES();//System.out.println(encrypDES.decrypt(code));System.out.println(encrypDES.encrypt("18011953567"));}/*public static void main(String[] args) {try {*//*String msg1 = "1";EncrypDES des1 = new EncrypDES();// 使用默认密钥System.out.println("加密前的字符:" + msg1);System.out.println("加密后的字符:" + des1.encrypt(msg1));System.out.println("解密后的字符:" + des1.decrypt(des1.encrypt(msg1)));*//**//* System.out.println("--------优美分隔符------");String msg2 = "1";String key =  "2020@#$2020";EncrypDES des2 = new EncrypDES(key);// 自定义密钥System.out.println("加密前的字符:" + msg2);System.out.println("加密后的字符:" + des2.encrypt(msg2));//c170d8716c90266dSystem.out.println("解密后的字符:" + des2.decrypt(des2.encrypt(msg2)));*//*} catch (Exception e) {e.printStackTrace();}}*/
}

 END

appkey、appSecret自动生成相关推荐

  1. 网关、开放平台如何设计appKey,appSecret,accessToken的生成和校验机制

    文章目录 总述 需求 整体设计 appKey的token管理 跑一跑,验证一下 结尾 总述 在开放平台或者网关中,经常会见到appKey,appSecret和accessToken,这是用来对open ...

  2. gorm存指针数据_gormt: gormt 是一个数据库映射工具,可以将 mysql 数据库自动生成 golang sturct 结构...

    mysql数据库转 struct 工具,可以将mysql数据库自动生成golang sturct结构,带大驼峰命名规则.带json标签 交互界面模式 ./gormt -g=true 命令行模式 ./g ...

  3. Java api文档自动生成工具smartdoc+torna

    首先,一般做java服务端都用过postman,并且都写过前端调用的api文档接口,并且也用过市面上的一些工具. API自文档动生成,能够省去了写文档的时间. 当然,当前也会有很多类似的开源工具,我们 ...

  4. IDEA自动生成对象所有set方法

    idea中有一款插件能够生成对象所有的set方法,GenerateAllSetter :下载地址 步骤1:将下载好的压缩包放在自己记得的文件夹中,在idea中进行导入 步骤2:在本地选中刚才的压缩包, ...

  5. IDEA中根据数据库自动生成实体类,并自定义所生成的实体类中的注解 @Table @Id @...

    使用IDEA项目添加Hibernate扩展,生成实体类并配置实体类中的注解 一.使用Hibernate自动生成实体类 1.在项目上右键,选择Add Framework Support找到 Hibern ...

  6. IDEA自动生成类注解,IDEA作者信息自动生成,IDEA类信息自动生成

    在新建类文件的时候自动生成注解,诸如我们常见的那些 作者,创建时间,TODO 等等 将以下格式的代码放在Settings -> File and Code Templates -> Inc ...

  7. FastAPI 自动生成的docs文档没法使用

    FastAPI 自动生成的docs文档没法使用,当展开路径时候一直在转圈,具体就是这样 这个是由于swagger-ui 3.30.1 中的bug导致,具体bug可以看这里 我们可以通过在FastAPI ...

  8. 自动生成低精度深度学习算子

    自动生成低精度深度学习算子 深度学习模型变得越来越大,越来越复杂,由于其有限的计算和能源预算,部署在低功耗电话和IoT设备上变得充满挑战.深度学习的最新趋势是使用高度量化的模型,该模型可对输入和几位权 ...

  9. 人脸照片自动生成游戏角色_ICCV2019论文解析

    人脸照片自动生成游戏角色_ICCV2019论文解析 Face-to-Parameter Translation for Game Character Auto-Creation 论文链接: http: ...

  10. IntelliJ IDEA下自动生成Hibernate映射文件以及实体类

    转自:https://blog.csdn.net/qq_34197553/article/details/77718925 1.构建项目并添加项目结构配置以及配置初始参数 1.1.如图将基本的架子搭建 ...

最新文章

  1. [翻译] - Inside SQL Server 2000's Memory Management Facilities
  2. 想快速发表CV/NLP论文?试试这几个方向!
  3. msp430编程用什么软件_UG编程是什么?ug编程做什么用的?
  4. 查询一个表中所有id字段在另一个表中对应值的SQL语句怎么写?
  5. 穷人最缺少的是什么?
  6. linux查询服务器的dns,如何查看Linux系统中DNS服务器的运行状况
  7. 二进制编译安装mysql_二进制编译安装mysql
  8. 单例模式代码_设计模式之单例:程序员必知必会,举例子+代码示例,通俗易懂...
  9. 米斯特白帽培训讲义(v2)信息收集
  10. 【2021牛客暑期多校训练营6】H Hopping Rabbit(扫描线)
  11. Matlab中数组的常见用法
  12. 一名技术leader的工作随笔
  13. python语言中浮点数_在Python中截断浮点数
  14. 【C语言】c语言练习题【2】(适合初学者)
  15. Duilib之挑战2048
  16. 数商云跨境电商供应链平台方案,提供全链条的跨境供应链服务
  17. 物联网无线传输技术有哪些?
  18. 【笔记】用Python写百度翻译网络爬虫
  19. ZYNQ-使用HDMI显示器进行SD卡图片读取显示
  20. WEB应用图片的格式,以及各自的特点和优化(一) by FungLeo

热门文章

  1. 物联网系统怎么部署服务器,如何搭建物联网云服务器
  2. cad2020打印样式放在哪个文件夹_CAD图形打印相关问题!
  3. 文献阅读(SRCNN)
  4. 管家婆mysql 数据库_Java数据库小项目02--管家婆项目
  5. 计算机应用技术的代码081401,学科、专业名称(代码).doc
  6. Leader安排的三小时工作量,我如何用python十秒完成
  7. 2020年CISP线下考试逐渐恢复啦
  8. STM32 低功耗STOP模式,RTC唤醒
  9. 【WIN】【C++】遍历文件夹下所有文件
  10. zemax输出ies_基于ZEMAX的光学设计教程(第2版)