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

  • 相关阅读:
    Java基础之十五 泛型
    设计模式之工厂模式
    数据结构之散列
    程序员的自我修养十内存
    程序员的自我修养一温故而知新
    Java编程思想之二十 并发
    Java编程思想之十八 枚举类型
    Java基础之十六 数组
    Java编程思想之十四 类型信息
    Java基础之十三 字符串
  • 原文地址:https://www.cnblogs.com/jourage/p/10319685.html
Copyright © 2020-2023  润新知