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

网站平台怎么做的好处莱芜民生广角

网站平台怎么做的好处,莱芜民生广角,wordpress 教學,求好用的seo软件简介 非对称加密#xff1a;加密和解密使用不同的秘钥的加解密方法。一般的#xff0c;用公钥做加密#xff0c;私钥做解密使用 常用的加解密有#xff1a;RSA、ECC、DSA#xff0c;在java中使用最多的是RSA 工具类 /*** 非对称加解密工具类(RSA)** RSA加密(一次)有最…简介 非对称加密加密和解密使用不同的秘钥的加解密方法。一般的用公钥做加密私钥做解密使用 常用的加解密有RSA、ECC、DSA在java中使用最多的是RSA 工具类 /*** 非对称加解密工具类(RSA)** RSA加密(一次)有最大字节数组限制 177、解密的最大字符限制128***/ public class AsymmetricEncryptDecryptionUtil {public static final String UTF8 StandardCharsets.UTF_8.name();public static final String ALGORITHM RSA;public static final int MAX_ENC_LENGTH 117;public static final int MAX_DEN_LENGTH 128;/*** 创建公钥和私钥对的16进制字符串** throws NoSuchAlgorithmException 算法异常* throws IOException io异常*/public static void createKeyPair() throws NoSuchAlgorithmException, IOException {KeyPairGenerator pairGenerator KeyPairGenerator.getInstance(ALGORITHM);pairGenerator.initialize(1024);KeyPair keyPair pairGenerator.genKeyPair();// 公钥PublicKey publicKey keyPair.getPublic();// 私钥PrivateKey privateKey keyPair.getPrivate();// 公钥秘钥字节数组byte[] publicKeyPairEncoded publicKey.getEncoded();// 私钥秘钥字节数组byte[] privateKeyEncoded privateKey.getEncoded();String pubHexStr Hex.encodeHexString(publicKeyPairEncoded);String priHexStr Hex.encodeHexString(privateKeyEncoded);System.out.println(公钥是: pubHexStr);System.out.println(私钥是: priHexStr);}private static PublicKey getPublicKey() throws Exception {String pubCfFile AsymmetricEncryptDecryptionUtil.class.getClassLoader().getResource(rsa.pub).getPath();String pubKeyHexStr FileUtils.readFileToString(new File(pubCfFile), UTF8);KeyFactory keyFactory KeyFactory.getInstance(ALGORITHM);X509EncodedKeySpec x509EncodedKeySpec new X509EncodedKeySpec(Hex.decodeHex(pubKeyHexStr));return keyFactory.generatePublic(x509EncodedKeySpec);}private static PrivateKey getPrivateKey() throws Exception {String priCfFile AsymmetricEncryptDecryptionUtil.class.getClassLoader().getResource(rsa.pri).getPath();String priKeyHexStr FileUtils.readFileToString(new File(priCfFile), UTF8);KeyFactory keyFactory KeyFactory.getInstance(ALGORITHM);PKCS8EncodedKeySpec pkcs8EncodedKeySpec new PKCS8EncodedKeySpec(Hex.decodeHex(priKeyHexStr));return keyFactory.generatePrivate(pkcs8EncodedKeySpec);}public static String encodeStr(String originalStr,Key key) throws Exception {Cipher cipher Cipher.getInstance(ALGORITHM);cipher.init(Cipher.ENCRYPT_MODE,key);byte[] bytes doCodec(cipher, originalStr.getBytes(UTF8), MAX_ENC_LENGTH);return Hex.encodeHexString(bytes);}public static String deCodeStr(String hexStr,Key key) throws Exception {byte[] bytes Hex.decodeHex(hexStr);Cipher cipher Cipher.getInstance(ALGORITHM);cipher.init(Cipher.DECRYPT_MODE,key);byte[] originalBytes doCodec(cipher,bytes,MAX_DEN_LENGTH);return new String(originalBytes,UTF8);}/*** 由于RSA加密、解密都有最大字节数组长度限制加密是177长度解密是128长度** 所以需要循环处理** param cipher cipher* param bytes 待加解密的字节数组* param maxLength 处理的最大长度* return 加解密的字节数组* throws BadPaddingException BadPaddingException* throws IllegalBlockSizeException IllegalBlockSizeException*/private static byte[] doCodec(Cipher cipher,byte[] bytes,int maxLength) throws BadPaddingException, IllegalBlockSizeException {int length bytes.length;int offset 0;byte[] cache;int i 0;ByteArrayOutputStream bos new ByteArrayOutputStream();while ((length - offset) 0) {if(length - offset maxLength) {cache cipher.doFinal(bytes,offset,maxLength);} else {cache cipher.doFinal(bytes,offset,length - offset);}i;offset i * maxLength;bos.write(cache,0,cache.length);}return bos.toByteArray();}public static void main(String[] args) throws Exception {String str 法律;PublicKey publicKey getPublicKey();String s encodeStr(str, publicKey);System.out.println(RSA encode result: s);PrivateKey privateKey getPrivateKey();String s1 deCodeStr(s,privateKey);System.out.println(RSA decode result: s1);} } 注意RSA加解密有限制一次加密的最大字节数组不能超过177长度解密的最大数组长度不能超过128个字节长度
http://www.zqtcl.cn/news/82334/

相关文章:

  • 昆明驿站网站建设织梦网站首页自动更新
  • 网站做有偿广告需要什么有序百度新闻源网站有哪些
  • 家纺 网站模版电子商务网站建设可用性五个方面
  • 百度做网站要多久专业制作网站价格
  • 宁波网站建设运营网上如何建网站卖量具
  • 国内有wix做的好的网站全包胶衣网站
  • 重庆做网站怎么做建设工程消防备案查询网站
  • 社保门户网站建设方案小松 建设项目 网站
  • 一个公司如何做多个网站备案成品网站灬源码1688
  • 雪狼网站系统如何做 行业社交类网站
  • 网站建设技术李京文企业文化建设内容主要包括
  • 视频网站开发php织梦个人网站模板
  • 甘肃建设住房厅网站首页商城设计app网站建设
  • 制作触屏版网站开发苏州吴江建设局招标网站
  • 丰城市城乡规划建设局网站网站的建设宗旨
  • 网站必须要实名认证么做淘宝客网站需要多大带宽
  • 广州网站建设有限公司网站300兆是多少钱
  • 兰州网站建设方案详细武威市市建设局网站建筑业管理
  • 佛山网站建设怎么办wordpress制作网站教程
  • ps做汽车网站下载地址北京装饰公司报价
  • 信息产业部网站备案网站开发项目人员安排
  • 安吉做网站百度推广登陆首页
  • 淘宝客网站开发平台利为汇wordpress
  • 网站模板修改工具网站开发语言什么意思
  • 昆明做网站软件wordpress云服务器安装教程
  • 做网站新科网站建设七初SEO网站建设
  • cq网络网站jquery 手机网站开发
  • 学校网站建设 应用情况软文500字范文
  • 网站建设网站建设教程推广网站方案
  • 查公司信息的网站白熊阅读做网站架构