zoukankan      html  css  js  c++  java
  • RSA算法加解密

    代码如下,RSA算法因为其解密的难度性是在支付行业很常见的的加密算法,java自带有自己的RSA算法包来对数据进行加解密,只需要导入相应的包就可以到达相应的效果。

    //解锁用户 ok
    	@Test
    	public void testUnlockMember(){
    		try{
    			System.out.println("testUnlockMember start");
    
    			JSONObject param = new JSONObject();
    			param.put("bizUserId", bizUserId);
    
    			System.out.println("request:" + param);
    			JSONObject response = client.request(soaName, "unlockMember", param);
    			System.out.println("response:" + response);
    
    			System.out.println("testUnlockMember end");
    		}catch(Exception e){
    			System.out.println("testUnlockMember error");
    			e.printStackTrace();
    		}
    	}
    
    	//RSA加密
    	@Test
    	public void testRsaEncrypt() throws Exception{
    		try{
    			System.out.println("rsaEncrypt start");
    
    			String str = "";
    
    			RSAUtil rsaUtil = new RSAUtil((RSAPublicKey)publicKey, (RSAPrivateKey)privateKey);
    			String encryptStr = rsaUtil.encrypt(str);
    			System.out.println(encryptStr);
    		}catch(Exception e){
    			System.out.println("rsaEncrypt error");
    			e.printStackTrace();
    			throw e;
    		}
    	}
    
    	//RSA加密
    	public String rsaEncrypt(String str) throws Exception{
    		try{
    			System.out.println("rsaEncrypt start");
    
    			RSAUtil rsaUtil = new RSAUtil((RSAPublicKey)publicKey, (RSAPrivateKey)privateKey);
    			String encryptStr = rsaUtil.encrypt(str);
    			return encryptStr;
    		}catch(Exception e){
    			System.out.println("rsaEncrypt error");
    			e.printStackTrace();
    			throw e;
    		}
    	}
    
    	//RSA解密
    	@Test
    	public void testRsaDecrypt() throws Exception{
    		try{
    			System.out.println("rsaDecrypt start");
    
    			String signStr = "";
    			RSAUtil rsaUtil = new RSAUtil((RSAPublicKey)publicKey, (RSAPrivateKey)privateKey);
    			String dencryptStr = rsaUtil.dencrypt(signStr);
    			System.out.println("解密:" + dencryptStr);
    		}catch(Exception e){
    			System.out.println("rsaDecrypt error");
    			e.printStackTrace();
    			throw e;
    		}
    	}
    }
    

      

    //解锁用户 ok@Testpublic void testUnlockMember(){try{System.out.println("testUnlockMember start");
    JSONObject param = new JSONObject();param.put("bizUserId", bizUserId);
    System.out.println("request:" + param);JSONObject response = client.request(soaName, "unlockMember", param);System.out.println("response:" + response);
    System.out.println("testUnlockMember end");}catch(Exception e){System.out.println("testUnlockMember error");e.printStackTrace();}}
    //RSA加密@Testpublic void testRsaEncrypt() throws Exception{try{System.out.println("rsaEncrypt start");
    String str = "";
    RSAUtil rsaUtil = new RSAUtil((RSAPublicKey)publicKey, (RSAPrivateKey)privateKey);String encryptStr = rsaUtil.encrypt(str);System.out.println(encryptStr);}catch(Exception e){System.out.println("rsaEncrypt error");e.printStackTrace();throw e;}}
    //RSA加密public String rsaEncrypt(String str) throws Exception{try{System.out.println("rsaEncrypt start");
    RSAUtil rsaUtil = new RSAUtil((RSAPublicKey)publicKey, (RSAPrivateKey)privateKey);String encryptStr = rsaUtil.encrypt(str);return encryptStr;}catch(Exception e){System.out.println("rsaEncrypt error");e.printStackTrace();throw e;}}
    //RSA解密@Testpublic void testRsaDecrypt() throws Exception{try{System.out.println("rsaDecrypt start");
    String signStr = "";RSAUtil rsaUtil = new RSAUtil((RSAPublicKey)publicKey, (RSAPrivateKey)privateKey);String dencryptStr = rsaUtil.dencrypt(signStr);System.out.println("解密:" + dencryptStr);}catch(Exception e){System.out.println("rsaDecrypt error");e.printStackTrace();throw e;}}}

  • 相关阅读:
    Tomcat安装(安装版)
    Selenium自动化测试(一)之环境搭建
    Windows快速启动应用高效搜索文件工具-Listary
    Python3之jsonpath使用和json转换
    Python3操作SQLite数据库
    初识面向对象
    忘记虚拟机中Linux的登录密码解决办法
    win10自带虚拟机的使用(Hyper-v)
    nigx下配置tp5.1路由
    PHP无限极菜单
  • 原文地址:https://www.cnblogs.com/jourage/p/10319685.html
Copyright © 2011-2022 走看看