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

网站建设及数据库设计毕业论文网络整合营销是什么意思

网站建设及数据库设计毕业论文,网络整合营销是什么意思,青岛本地网站,wordpress火车头采集免费版Java(110):非对称加密RSA的使用(KeyPair生成密钥) RSA 算法是一种非对称加解密算法。服务方生成一对 RSA 密钥,即公钥 私钥,将公钥提供给调用方,调用方使用公钥对数据进行加密后,服务方根据私钥进行解密。 1、RSA生…

Java(110):非对称加密RSA的使用(KeyPair生成密钥)

RSA 算法是一种非对称加解密算法。服务方生成一对 RSA 密钥,即公钥 + 私钥,将公钥提供给调用方,调用方使用公钥对数据进行加密后,服务方根据私钥进行解密。

1、RSA生成密钥方法

        keyPairGen.initialize(1024);//生成"密钥对"对象KeyPair keyPair = keyPairGen.generateKeyPair();//分别获取私钥和公钥对象RSAPrivateKey PrivateKey =(RSAPrivateKey) keyPair.getPrivate();RSAPublicKey publicKey =(RSAPublicKey) keyPair.getPublic();

2、RSA加密和解密方法

   /*** 公钥加密* @param publicKey 公钥* @param obj 明文* @return byte[] 密文*/public static byte[] encrypt(RSAPublicKey publicKey, byte[] obj) throws Exception {Cipher cipher =Cipher.getInstance("RSA");cipher.init(Cipher.ENCRYPT_MODE,publicKey);//返回加密后的内容return cipher.doFinal(obj);}/*** 私钥解密* @param privateKey 公钥* @param obj 密文* @return byte[] 密文*/public static byte[] decrypt(RSAPrivateKey privateKey, byte[] obj)throws Exception {Cipher cipher = Cipher.getInstance("RSA");cipher.init(Cipher.DECRYPT_MODE, privateKey);//返回解密后的数组return cipher.doFinal(obj);}

3、Base64编码和解码

maven

<dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.11</version>
</dependency>
    /*** 编码* @param txt byte字节数组* @return encode Base64编码*/public static byte[] encode(byte[] txt) {return org.apache.commons.codec.binary.Base64.encodeBase64(txt);}/*** 解码* @param txt 编码后的byte* @return decode Base64解码*/public static byte[] decode(String txt){return org.apache.commons.codec.binary.Base64.decodeBase64(txt);}

4、调用加解密

    public static void main(String[] args)throws Exception {//获取RSA算法的密钥生成器对象KeyPairGenerator keyPairGen =KeyPairGenerator.getInstance("RSA");//设定密钥长度为1024位keyPairGen.initialize(1024);//生成"密钥对"对象KeyPair keyPair = keyPairGen.generateKeyPair();//分别获取私钥和公钥对象RSAPrivateKey PrivateKey =(RSAPrivateKey) keyPair.getPrivate();RSAPublicKey publicKey =(RSAPublicKey) keyPair.getPublic();//执行加密和解密过程String InData="Hello World!";//得到要加密内容的数组byte[] byteInData =InData.getBytes("UTF-8");//用公钥加密byte[] cipherByte= encrypt(publicKey,byteInData);  //RSA加密String cipher=new String(encode(cipherByte));   //Base64a编码System.out.println("公钥加密,密文:"+cipher);//用私钥解密byte[] plain =decrypt(PrivateKey,decode(cipher)); //Base64a解码System.out.println("私钥解密,明文:"+new String(plain)); //RSA解密}

5、RSA加解密代码示例:

package jmj;import javax.crypto.Cipher;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;/*** Description :** @author : HMF* Date : Created in 20:32 2023/3/13* @version :*/
public class RSATest {public static void main(String[] args)throws Exception {//获取RSA算法的密钥生成器对象KeyPairGenerator keyPairGen =KeyPairGenerator.getInstance("RSA");//设定密钥长度为1024位keyPairGen.initialize(1024);//生成"密钥对"对象KeyPair keyPair = keyPairGen.generateKeyPair();//分别获取私钥和公钥对象RSAPrivateKey PrivateKey =(RSAPrivateKey) keyPair.getPrivate();RSAPublicKey publicKey =(RSAPublicKey) keyPair.getPublic();//执行加密和解密过程String InData="Hello World!";//得到要加密内容的数组byte[] byteInData =InData.getBytes("UTF-8");//用公钥加密byte[] cipherByte= encrypt(publicKey,byteInData);  //RSA加密String cipher=new String(encode(cipherByte));   //Base64a编码System.out.println("公钥加密,密文:"+cipher);//用私钥解密byte[] plain =decrypt(PrivateKey,decode(cipher)); //Base64a解码System.out.println("私钥解密,明文:"+new String(plain)); //RSA解密}/*** 编码* @param txt byte字节数组* @return encode Base64编码*/public static byte[] encode(byte[] txt) {return org.apache.commons.codec.binary.Base64.encodeBase64(txt);}/*** 解码* @param txt 编码后的byte* @return decode Base64解码*/public static byte[] decode(String txt){return org.apache.commons.codec.binary.Base64.decodeBase64(txt);}/*** 公钥加密* @param publicKey 公钥* @param obj 明文* @return byte[] 密文*/public static byte[] encrypt(RSAPublicKey publicKey, byte[] obj) throws Exception {Cipher cipher =Cipher.getInstance("RSA");cipher.init(Cipher.ENCRYPT_MODE,publicKey);//返回加密后的内容return cipher.doFinal(obj);}/*** 私钥解密* @param privateKey 公钥* @param obj 密文* @return byte[] 密文*/public static byte[] decrypt(RSAPrivateKey privateKey, byte[] obj)throws Exception {Cipher cipher = Cipher.getInstance("RSA");cipher.init(Cipher.DECRYPT_MODE, privateKey);//返回解密后的数组return cipher.doFinal(obj);}}

执行结果:

 

参考:https://blog.csdn.net/piaoranyuji/article/details/126140261

http://www.hkea.cn/news/604979/

相关文章:

  • 备案 网站名称怎么写crm软件
  • 扁平式网站模板b2b网站推广优化
  • 做外贸网站网络营销咨询服务
  • 江门网站建设方案报价淘宝seo优化怎么做
  • 盘龙城做网站推广网站推广
  • 如何做电子书网站域名站长工具
  • 物联网平台有哪些排名优化外包公司
  • 秦皇岛汽车网站制作数字营销工具
  • 培训教育的网站怎么做东莞做网站的联系电话
  • 云南做网站的公司外贸谷歌优化
  • 网页设计学徒培训可试学巢湖seo推广
  • 让顾客心动的句子seo模拟点击软件源码
  • 设计类专业包括哪些kj6699的seo综合查询
  • 手机网站制作哪家好查关键词
  • 米拓企业网站管理系统电商培训机构排名前十
  • 做效果图有哪些网站seo点击排名
  • 网络营销推广网站收录seo推广排名平台有哪些
  • 产品经理如何看待网站开发广州软件系统开发seo推广
  • wordpress 忘记管理员如何做网站seo
  • app和网站哪个有优势淘宝关键词排名
  • wordpress该域名宁波网站seo公司
  • 建购物网站怎么建呀简单的网站建设
  • 江苏省建设教育协会网站首页百度知道合伙人答题兼职入口
  • 做优化的网站平台搭建
  • 做网站需要多久网络推广是什么专业
  • 厦门加盟网站建设线上推广营销
  • 定制网站案例seo搜索引擎优化薪酬
  • 网站制作成功后怎么使用浏览器观看b站视频的最佳设置
  • 一家专门做开网店的网站北京seo专员
  • 专业企业网站搭建服务头条权重查询