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

  • 相关阅读:
    获取发布的头条的url,避免点击打开新的页面
    下载图片 保存至本地 返回路径
    线程运行的3个状态
    程序并发执行所需付出的时空开销
    web metrics dashboard 数据分析工具 看板 从可视化发现问题 避免sql重复写 调高效率
    Binary safe
    simple dynamic string
    a
    a
    从业务角度 减少代码执行的时间 和 因长时间执行的而带来的代码复杂性 日志恢复数据
  • 原文地址:https://www.cnblogs.com/jourage/p/10319685.html
Copyright © 2011-2022 走看看