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;}}}

  • 相关阅读:
    Mysql JSON 新特性用法
    fastjson 使用技巧
    kafka 笔记
    nginx 使用教程
    spring boot 和 spring mvc 使用 jackson 包处理 忽略 null 字段返回
    jmeter 安装使用
    windows 下千万不要用 git的“换行符自动转换功能”
    ps grep awk 结合 xargs kill进程
    linux发行版版本及内核查看
    union 跟 order by同时使用
  • 原文地址:https://www.cnblogs.com/jourage/p/10319685.html
Copyright © 2011-2022 走看看