• 大小: 46KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-11
  • 语言: Java
  • 标签:

资源简介

UDP协议实现对等通讯Java+RSA加密解密传送信息实现,有client端和server端

资源截图

代码片段和文件信息

package myrsa2;

import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.HashMap;

public class RSATest
{
public static void main(String[] args) throws Exception 
{  
        // TODO Auto-generated method stub  
        HashMapject> map = RSAUtils.getKeys();  
        //生成公钥和私钥  
        RSAPublicKey publicKey = (RSAPublicKey) map.get(“public“);  
        RSAPrivateKey privateKey = (RSAPrivateKey) map.get(“private“);  
        System.out.print(“\npublicKey:“+publicKey);
        System.out.print(“\nprivateKey:“+privateKey);
        //模  
        String modulus = publicKey.getModulus().toString();  
        //公钥指数  
        String public_exponent = publicKey.getPublicExponent().toString();  
        //私钥指数  
        String private_exponent = privateKey.getPrivateExponent().toString(); 
        System.out.print(“\nmodulus:“+modulus);
        System.out.print(“\npublic_exponent:“+public_exponent); 
        System.out.print(“\nprivate_exponent:“+private_exponent);
        
        //明文  
        String ming = “jjjjj123456789“;  
        //使用模和指数生成公钥和私钥  
        RSAPublicKey pubKey = RSAUtils.getPublicKey(modulus public_exponent);  
        RSAPrivateKey priKey = RSAUtils.getPrivateKey(modulus private_exponent);  
        //加密后的密文  
        String mi = RSAUtils.encryptByPublicKey(ming pubKey);
        System.out.print(“\n加密前ming:“+ming);
        System.out.print(“\n加密前ming_lenth:“+ming.length());
        //System.out.print(“\npubKey:“+pubKey); 
        //System.out.print(“\npriKey:“+priKey);
        System.out.print(“\n加密后mi:“+mi);
        System.out.print(“\n解密前ming_lenth:“+mi.length());
        //解密后的明文  
        ming = RSAUtils.decryptByPrivateKey(mi priKey); 
        
        System.out.print(“\n解密后的明文:“+ming);
        //System.err.println(ming);  
        
        
        
        
/* String modulus = “104344065049535235337602750745972062206029307981021347712560211453856339371441553987973583092897777954138410872748183586468653712704255491417965770505559379560464351555212396558781035059397673682011104226754831711072822991514780158821061675743098642785196847109412740308768227675829387795015925250708654667999“;  
     //公钥指数  
     String public_exponent = “65537“;  
     //私钥指数  
     String private_exponent = “26190699453207419035103304236862236954532281250099961393893761972869322408108603736853463568338014363574421454395343393768548355493614337455567647661877282282990417681871242149491729973582918161723756665580166306049786985876261601361679056199457576596963451088706448549329113352190937000411497436484850157873“; 
    
     System.out.print(“\nmodulus:“+modulus);
     System.out.print(“\npublic_exponent:“+public_exponent); 
     System.out.print(“\nprivate_exponent:“+private_exponent);
        
     //明文  
    // String ming = “jjjjj123456789“;  
     //使用模和指数生成公钥和私钥  
     RSAPublicKey pubKey = RSA

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        301  2016-06-20 21:13  UDPClient\.classpath

     文件        385  2016-06-21 15:48  UDPClient\.project

     文件        598  2016-06-20 21:13  UDPClient\.settings\org.eclipse.jdt.core.prefs

     文件        763  2016-06-23 22:09  UDPClient\bin\client_window\ClientWindow$1.class

     文件        728  2016-06-23 22:09  UDPClient\bin\client_window\ClientWindow$2.class

     文件        716  2016-06-23 22:09  UDPClient\bin\client_window\ClientWindow$3.class

     文件       8621  2016-06-23 22:09  UDPClient\bin\client_window\ClientWindow.class

     文件       2777  2016-06-24 21:02  UDPClient\bin\myrsa2\RSATest.class

     文件       6513  2016-06-23 22:09  UDPClient\bin\myrsa2\RSAUtils.class

     文件        732  2016-06-24 21:02  UDPClient\bin\win1\ClientWindow1$1.class

     文件        689  2016-06-24 21:02  UDPClient\bin\win1\ClientWindow1$2.class

     文件       7511  2016-06-24 21:02  UDPClient\bin\win1\ClientWindow1.class

     文件       7164  2016-06-24 20:58  UDPClient\src\myrsa2\RSATest.java

     文件       6076  2016-06-19 11:00  UDPClient\src\myrsa2\RSAUtils.java

     文件       6757  2016-06-24 21:02  UDPClient\src\win1\ClientWindow1.java

     文件        301  2016-06-20 21:59  UDPServer\.classpath

     文件        385  2016-06-21 15:48  UDPServer\.project

     文件        598  2016-06-20 21:59  UDPServer\.settings\org.eclipse.jdt.core.prefs

     文件       2652  2016-06-23 22:09  UDPServer\bin\myrsa2\RSATest.class

     文件       6513  2016-06-23 22:09  UDPServer\bin\myrsa2\RSAUtils.class

     文件        763  2016-06-23 22:09  UDPServer\bin\server_window\ServerWindow$1.class

     文件        728  2016-06-23 22:09  UDPServer\bin\server_window\ServerWindow$2.class

     文件        716  2016-06-23 22:09  UDPServer\bin\server_window\ServerWindow$3.class

     文件       8704  2016-06-23 22:09  UDPServer\bin\server_window\ServerWindow.class

     文件        732  2016-06-24 21:02  UDPServer\bin\win1\ServerWindow1$1.class

     文件        689  2016-06-24 21:02  UDPServer\bin\win1\ServerWindow1$2.class

     文件       7838  2016-06-24 21:02  UDPServer\bin\win1\ServerWindow1.class

     文件       3312  2016-06-19 11:36  UDPServer\src\myrsa2\RSATest.java

     文件       6076  2016-06-19 11:00  UDPServer\src\myrsa2\RSAUtils.java

     文件       7272  2016-06-24 21:02  UDPServer\src\win1\ServerWindow1.java

............此处省略21个文件信息

评论

共有 条评论

相关资源