当前位置: 首页 > news >正文

网站开发比较厉害有道搜索

网站开发比较厉害,有道搜索,wordpress dux5.2主题,用什么程序做网站好前言项目里需要用到sm4加密#xff0c;在这里记录一下(springboot)。依赖bouncycastleorg.bouncycastlebcmail-jdk15on1.66cn.hutoolhutool-all5.4.1代码直接贴代码#xff0c;可以根据自己的需要封装相对应的代码逻辑。//需要注意的是#xff0c;使用KeyGenerator生成密钥种…前言项目里需要用到sm4加密在这里记录一下(springboot)。依赖bouncycastleorg.bouncycastlebcmail-jdk15on1.66cn.hutoolhutool-all5.4.1代码直接贴代码可以根据自己的需要封装相对应的代码逻辑。//需要注意的是使用KeyGenerator生成密钥种子的时候windows和linux上会产生不一致。//例如KeyGenerator kg KeyGenerator.getInstance(ALGORITHM_NAME, PROVIDER_NAME);SecureRandom random new SecureRandom();if(null ! seed !.equals(seed)){random.setSeed(seed.getBytes());}kg.init(keySize, random);//解决办法SecureRandom random SecureRandom.getInstance(SHA1PRNG);import cn.hutool.core.util.HexUtil;import com.spinfo.common.constants.UserConstants;import com.spinfo.controller.UserController;import org.bouncycastle.jce.provider.BouncyCastleProvider;import org.bouncycastle.util.encoders.Base64;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.util.DigestUtils;import javax.crypto.*;import javax.crypto.spec.IvParameterSpec;import javax.crypto.spec.SecretKeySpec;import java.security.*;import java.util.Arrays;public class SM4Util {private static Logger logger LoggerFactory.getLogger(SM4Util.class);private static final String PROVIDER_NAME BC;public static final String ALGORITHM_NAME SM4;public static final String ALGORITHM_NAME_ECB_PADDING SM4/ECB/PKCS5Padding;public static final String ALGORITHM_NAME_CBC_PADDING SM4/CBC/PKCS5Padding;public static final String DEFAULT_KEY random_seed;public static final int DEFAULT_KEY_SIZE 128;private static final int ENCRYPT_MODE 1;private static final int DECRYPT_MODE 2;static {Security.addProvider(new BouncyCastleProvider());}public static byte[] generateKey() throws NoSuchAlgorithmException, NoSuchProviderException {return generateKey(DEFAULT_KEY, DEFAULT_KEY_SIZE);}public static byte[] generateKey(String seed) throws NoSuchAlgorithmException, NoSuchProviderException {return generateKey(seed, DEFAULT_KEY_SIZE);}public static byte[] generateKey(String seed, int keySize) throws NoSuchAlgorithmException, NoSuchProviderException {KeyGenerator kg KeyGenerator.getInstance(ALGORITHM_NAME, PROVIDER_NAME);SecureRandom random SecureRandom.getInstance(SHA1PRNG);if(null ! seed !.equals(seed)){random.setSeed(seed.getBytes());}kg.init(keySize, random);return kg.generateKey().getEncoded();}/*** ecb 加密* param key* param data*/public static byte[] encryptEcbPadding(byte[] key, byte[] data) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {Cipher cipher generateEcbCipher(ENCRYPT_MODE, key);return cipher.doFinal(data);}/*** ecb 解密* param key* param cipherText*/public static byte[] decryptEcbPadding(byte[] key, byte[] cipherText) throws IllegalBlockSizeException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException {Cipher cipher generateEcbCipher(DECRYPT_MODE, key);return cipher.doFinal(cipherText);}/*** cbc 加密* param key* param data*/public static byte[] encryptCbcPadding(byte[] key, byte[] iv, byte[] data) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {Cipher cipher generateCbcCipher(ENCRYPT_MODE, key, iv);return cipher.doFinal(data);}public static String encryptCbcPaddingString(byte[] key, byte[] iv, byte[] data) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException {Cipher cipher generateCbcCipher(ENCRYPT_MODE, key, iv);byte[] result cipher.doFinal(data);return Base64.toBase64String(result);}/*** cbc 解密* param key* param iv* param cipherText*/public static byte[] decryptCbcPadding(byte[] key, byte[] iv, String cipherText) throws IllegalBlockSizeException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidAlgorithmParameterException {byte[] cipherBytes Base64.decode(cipherText);Cipher cipher generateCbcCipher(DECRYPT_MODE, key, iv);return cipher.doFinal(cipherBytes);}public static byte[] decryptCbcPadding(byte[] key, byte[] iv, byte[] cipherText) throws IllegalBlockSizeException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidAlgorithmParameterException {Cipher cipher generateCbcCipher(DECRYPT_MODE, key, iv);return cipher.doFinal(cipherText);}/*** ecb cipher* param mode* param key* return*/private static Cipher generateEcbCipher(int mode, byte[] key) throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException {Cipher cipher Cipher.getInstance(ALGORITHM_NAME_ECB_PADDING, PROVIDER_NAME);Key sm4Key new SecretKeySpec(key, ALGORITHM_NAME);cipher.init(mode, sm4Key);return cipher;}/*** cbc cipher* param mode* param key* return*/private static Cipher generateCbcCipher(int mode, byte[] key, byte[] iv) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException {Cipher cipher Cipher.getInstance(ALGORITHM_NAME_CBC_PADDING, PROVIDER_NAME);Key sm4Key new SecretKeySpec(key, ALGORITHM_NAME);IvParameterSpec ivParameterSpec new IvParameterSpec(iv);cipher.init(mode, sm4Key, ivParameterSpec);return cipher;}/*** ecb 加密 times 次* param data* param salt* param times* return*/public static String encryptEcbDataTimes(String data, String salt, int times) throws GeneralSecurityException {try {byte[] key HexUtil.decodeHex(salt);byte[] bytes data.getBytes();for(int i 0; i times; i) {bytes encryptEcbPadding(key, bytes);}data Base64.toBase64String(bytes);return data;} catch (BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException var5) {throw new GeneralSecurityException(SM4加密失败);}}/*** ecb 解密 times 次* param data* param salt* param times* return* throws GeneralSecurityException*/public static String decryptEcbDataTimes(String data, String salt, int times) throws GeneralSecurityException {try {byte[] bytes Base64.decode(data);byte[] key HexUtil.decodeHex(salt);for(int i 0; i times; i) {bytes decryptEcbPadding(key, bytes);}data new String(bytes);return data;} catch (BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException var5) {throw new GeneralSecurityException(SM4解密失败);}}/*** cbc 加密 times 次* param data* param salt* param times* return*/public static String encryptCbcDataTimes(String data, String salt, int times) {try {byte[] iv generateKey();byte[] key generateKey(salt);byte[] bytes data.getBytes();Cipher cipher generateCbcCipher(ENCRYPT_MODE, key, iv);for(int i 0; i times; i) {bytes cipher.doFinal(bytes);}data Base64.toBase64String(bytes);return data;} catch (Exception e) {e.printStackTrace();return null;}}/*** cbc 解密 times 次* param data* param salt* param times* return* throws GeneralSecurityException*/public static String decryptCbcDataTimes(String data, String salt, int times) throws GeneralSecurityException {try {byte[] iv generateKey();byte[] bytes Base64.decode(data);byte[] key generateKey(salt);Cipher cipher generateCbcCipher(ENCRYPT_MODE, key, iv);for(int i 0; i times; i) {bytes cipher.doFinal(bytes);}data new String(bytes);return data;} catch (BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException var5) {throw new GeneralSecurityException(SM4解密失败);}}}
http://www.sadfv.cn/news/255721/

相关文章:

  • 静态网站制作流程浙江平湖建设局网站
  • 网站开发所需人员小型培训机构管理系统
  • 网站优化营销wordpress显示所有文章列表
  • 学做网站学费集团网站建设哪家好
  • h5网站制作案例分析视频网站是用什么框架做的
  • 网站建设服务费属于什么科目余姚汽车网站建设
  • 做网站有骗子小型购物网站
  • 福州网站建设金森今天的最新消息
  • 个人能做网站吗新华美玉官方网站在线做
  • 深圳营销型网站制作公司企业网站 html模板
  • php+mysql网站开发全程实例 下载asp美食网站源码
  • 微网站开发怎么写网络营销实现方式有哪些
  • 小的电商网站公司高端网站建设
  • 牟平网站建设苏州定制网站建设
  • 云南网站推广网站模板 免费
  • 扬州住房与城乡建设局网站哈尔滨seo优化公司多少钱
  • 外贸服装网站开发量化交易网站开发
  • 网站建设需要提供功能目录吗大连关键词排名系统
  • 学校的网站开发过程新手如何写公众号文章
  • html 做网站的模板大连网站建设微信群
  • 深圳网站建设东营wordpress如何配置文件
  • 直接登录的网站优客教育网页制作教程
  • 网站开发视频资源放哪儿南宁正规的seo费用
  • 网站首页 psd智能魔方网站
  • 江阴企业网站制作学校网站开发工程师
  • 水电维修在哪个网站上做推广好些前端网站建设插件
  • 有侧边栏的网站用c 做网站设计系统的项目作业
  • 公司网站数媒设计制作推广文案撰写
  • 矿区网站建设学做网站要代码
  • 怎么做网站网页归档温州品牌推广