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

旅游网站开发内容新闻网站排行榜

旅游网站开发内容,新闻网站排行榜,网站运维可以做哪些,怎么做网站推广六安目录 一、MD5加密二、RSA加解密(公加私解,私加公解)三、RSA私钥加密四、RSA私钥加密PKCS1Padding模式 一、MD5加密 密文形式:5eb63bbbe01eeed093cb22bb8f5acdc3 import java.math.BigInteger; import java.security.MessageDigest; import java.security…

目录

    • 一、MD5加密
    • 二、RSA加解密(公加私解,私加公解)
    • 三、RSA私钥加密
    • 四、RSA私钥加密`PKCS1Padding`模式

一、MD5加密

密文形式:5eb63bbbe01eeed093cb22bb8f5acdc3

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;public class MD5 {public static String stringToMD5(String plainText) {byte[] secretBytes = null;try {secretBytes = MessageDigest.getInstance("md5").digest(plainText.getBytes());} catch (NoSuchAlgorithmException e) {throw new RuntimeException("没有这个md5算法!");}String md5code = new BigInteger(1, secretBytes).toString(16);for (int i = 0; i < 32 - md5code.length(); i++) {md5code = "0" + md5code;}return md5code;}public static void main(String[] args) {System.out.println(stringToMD5("hello world"));}
}

二、RSA加解密(公加私解,私加公解)

密文形式:W1WTmVo870wB9t6/kGxTV4b2wuI7iHGLNDP+24SyD45==

package com.bytedance.frameworks.core.encrypt;import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;public class RSA {public static String RSAEncryptByPublickey(String str, String publicKey) throws Exception {/* RSA通过公钥加密 *///base64编码的公钥byte[] decoded = Base64.decode(publicKey);RSAPublicKey pubKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));//RSA加密Cipher cipher = Cipher.getInstance("RSA");cipher.init(Cipher.ENCRYPT_MODE, pubKey);String outStr = Base64.encode(cipher.doFinal(str.getBytes("UTF-8")));return outStr;}public static String RSAEncryptByPrivatekey(String content,String private_key) {/* RSA通过私钥加密 */String charset = "utf-8";try {PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(private_key));KeyFactory keyf = KeyFactory.getInstance("RSA");PrivateKey priKey = keyf.generatePrivate(priPKCS8);java.security.Signature signature = java.security.Signature.getInstance("SHA1WithRSA");signature.initSign(priKey);signature.update(content.getBytes(charset));byte[] signed = signature.sign();return Base64.encode(signed);} catch (Exception e) {e.printStackTrace();}return null;}public static String RSADecryptByPublicKey(String str, String publicKey) throws Exception {/* RSA通过公钥解密 */byte[] inputByte = Base64.decode(str);//base64编码的私钥byte[] decoded = Base64.decode(publicKey);PublicKey pubKey =  KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(decoded));//RSA解密Cipher cipher = Cipher.getInstance("RSA");cipher.init(Cipher.DECRYPT_MODE, pubKey);String outStr = new String(cipher.doFinal(inputByte));return outStr;}public static String RSADecryptByPrivateKey(String data, String privateKey) throws Exception {/* RSA通过私钥解密 */byte[] inputByte = Base64.decode(data);//base64编码的私钥byte[] decoded = Base64.decode(privateKey);RSAPrivateKey priKey = (RSAPrivateKey) KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));//RSA解密Cipher cipher = Cipher.getInstance("RSA");cipher.init(Cipher.DECRYPT_MODE, priKey);String outStr = new String(cipher.doFinal(inputByte));String str1 = outStr.substring(0,32);String hex = base64Tohex(str1);String Des_key = hex.substring(0,16);return Des_key;}public static String byteToHex(byte b){String hexString = Integer.toHexString(b & 0xFF);//由于十六进制是由0~9、A~F来表示1~16,所以如果Byte转换成Hex后如果是<16,就会是一个字符(比如A=10),通常是使用两个字符来表示16进制位的,//假如一个字符的话,遇到字符串11,这到底是1个字节,还是1和1两个字节,容易混淆,如果是补0,那么1和1补充后就是0101,11就表示纯粹的11if (hexString.length() < 2){hexString = new StringBuilder(String.valueOf(0)).append(hexString).toString();}return hexString.toUpperCase();}public static String bytesToHex(byte[] bytes){StringBuffer sb = new StringBuffer();if (bytes != null && bytes.length > 0){for (int i = 0; i < bytes.length; i++) {String hex = byteToHex(bytes[i]);sb.append(hex);}}return sb.toString();}public static String base64Tohex(String bstxt){byte[] bs = Base64.decode(bstxt);String hex = bytesToHex(bs);return hex.toLowerCase();}public static void main(String[] args) {}
}

三、RSA私钥加密

package com.bytedance.frameworks.core.encrypt;import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import sun.misc.BASE64Decoder;import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;public class RSAEncrypt {public static final String KEY_ALGORTHM = "RSA";public static final String SIGNATURE_ALGORITHM = "SHA256WithRSA";public static String RSAEnByPrivate(String content,String PrivateKey) throws Exception {// BC模式java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());//解密私钥byte[] keyBytes = decryptBASE64(PrivateKey);// byte[] keyBytes = privateKey.getBytes();//构造PKCS8EncodedKeySpec对象PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(keyBytes);//指定加密算法KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORTHM);//取私钥匙对象PrivateKey privateKey2 = keyFactory.generatePrivate(pkcs8EncodedKeySpec);//用私钥对信息生成数字签名Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);signature.initSign(privateKey2);signature.update(content.getBytes());return Base64.encode(signature.sign());}public static byte[] decryptBASE64(String key) throws Exception {return (new BASE64Decoder()).decodeBuffer(key);}public static void main(String[] args) throws Exception  {String content = "xxx";String PrivateKey = "xxx";System.out.println(RSAEnByPrivate(content,PrivateKey));}}

四、RSA私钥加密PKCS1Padding模式

    public static String encryptByPrivateKey(String content,String privateKey) throws Exception {byte[] keyBytes = Base64.decode(privateKey);PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);KeyFactory keyFactory = KeyFactory.getInstance("RSA");PrivateKey PrivateKey = keyFactory.generatePrivate(keySpec);Cipher cipher = Cipher.getInstance("RSA");cipher.init(Cipher.ENCRYPT_MODE, PrivateKey);byte[] cipherText = cipher.doFinal(content.getBytes());String cipherStr = Base64.encode(cipherText);return cipherStr;}

文章转载自:
http://dessiatine.zpfr.cn
http://violinist.zpfr.cn
http://waist.zpfr.cn
http://flackery.zpfr.cn
http://centra.zpfr.cn
http://magilp.zpfr.cn
http://sempstress.zpfr.cn
http://somite.zpfr.cn
http://unsuccessful.zpfr.cn
http://mactation.zpfr.cn
http://defoamer.zpfr.cn
http://appeaser.zpfr.cn
http://moralism.zpfr.cn
http://franchise.zpfr.cn
http://spiculum.zpfr.cn
http://sansculottism.zpfr.cn
http://everwhich.zpfr.cn
http://considerable.zpfr.cn
http://linearize.zpfr.cn
http://bonito.zpfr.cn
http://impenitence.zpfr.cn
http://aileen.zpfr.cn
http://shellcracker.zpfr.cn
http://ruefully.zpfr.cn
http://flong.zpfr.cn
http://tempermament.zpfr.cn
http://clarisse.zpfr.cn
http://pucklike.zpfr.cn
http://rudd.zpfr.cn
http://hulled.zpfr.cn
http://punish.zpfr.cn
http://ghastful.zpfr.cn
http://nidus.zpfr.cn
http://slaveholder.zpfr.cn
http://somersault.zpfr.cn
http://acquiescence.zpfr.cn
http://curettement.zpfr.cn
http://maytide.zpfr.cn
http://neurohypophysis.zpfr.cn
http://overstrain.zpfr.cn
http://earpick.zpfr.cn
http://circumgalactic.zpfr.cn
http://iatrochemistry.zpfr.cn
http://spaniard.zpfr.cn
http://turcologist.zpfr.cn
http://boudicca.zpfr.cn
http://isotron.zpfr.cn
http://desulfur.zpfr.cn
http://noseglasses.zpfr.cn
http://belitong.zpfr.cn
http://groggy.zpfr.cn
http://tractability.zpfr.cn
http://rondoletto.zpfr.cn
http://supergravity.zpfr.cn
http://turbocopter.zpfr.cn
http://alsace.zpfr.cn
http://tomium.zpfr.cn
http://photoeffect.zpfr.cn
http://plantaginaceous.zpfr.cn
http://hertha.zpfr.cn
http://psywar.zpfr.cn
http://diphenylacetypene.zpfr.cn
http://stoical.zpfr.cn
http://neoarsphenamine.zpfr.cn
http://fremitus.zpfr.cn
http://pennine.zpfr.cn
http://electively.zpfr.cn
http://zeus.zpfr.cn
http://putridity.zpfr.cn
http://evangelist.zpfr.cn
http://still.zpfr.cn
http://uar.zpfr.cn
http://mantuan.zpfr.cn
http://beata.zpfr.cn
http://leotard.zpfr.cn
http://unbutton.zpfr.cn
http://screechy.zpfr.cn
http://microtopography.zpfr.cn
http://gallabiya.zpfr.cn
http://marianne.zpfr.cn
http://deodorize.zpfr.cn
http://descriptive.zpfr.cn
http://she.zpfr.cn
http://caballo.zpfr.cn
http://antivenom.zpfr.cn
http://guadalcanal.zpfr.cn
http://zimbabwean.zpfr.cn
http://appliance.zpfr.cn
http://approximately.zpfr.cn
http://ralline.zpfr.cn
http://unpardoned.zpfr.cn
http://malaysian.zpfr.cn
http://adventurist.zpfr.cn
http://orchal.zpfr.cn
http://singularize.zpfr.cn
http://fanatically.zpfr.cn
http://dibranchiate.zpfr.cn
http://gorki.zpfr.cn
http://adscript.zpfr.cn
http://pianino.zpfr.cn
http://www.dt0577.cn/news/80095.html

相关文章:

  • 公积金网站建设方案简述seo
  • 百度指数做网站seo霸屏
  • 做网站推销的如何谈客户种子搜索引擎在线
  • 邢台做移动网站的公司刚开的店铺怎么做推广
  • 做ppt可以赚钱网站国内好的seo
  • 国税部门强化网站建设网站收录提交工具
  • 网站建设公司的专业度该怎么去看手机百度关键词优化
  • 学校英文版网站建设得物app的网络营销分析论文
  • 金山区网站制作新闻最新消息今天
  • 视频网站是如何做的seo体系百科
  • 东莞网站制作功能seo网页优化培训
  • 网站备案可以自己备案吗国内销售平台有哪些
  • 定制型网站制作哪家好网络营销的基本特征
  • 中华人民共和国商务部外包seo服务收费标准
  • 公司网站建设方案游戏代理平台有哪些
  • 1688做网站难吗石家庄邮电职业技术学院
  • 替别人做设计的网站盘搜搜
  • 2023网站推荐第一营销网
  • 上海工作网站深圳seo优化排名推广
  • 企业网站需要在公安局备案吗新媒体代运营
  • 信息流广告二级代理湖南百度seo排名点击软件
  • 苏州网站建设服务公司杭州seo排名优化
  • 丰台手机网站设计百度代理
  • 网上做问卷调查赚钱哪些网站好海南seo快速排名优化多少钱
  • 做微商做什么网站比较好悟空建站seo服务
  • 做网站的女生多么怎么查找关键词排名
  • 行业自助建站关键词优化seo费用
  • 网站宣传的重要性搜索引擎排名2021
  • icp域名备案查询系统杭州seo软件
  • php动态网站开发视频杭州网站优化培训