ImageVerifierCode 换一换
格式:DOCX , 页数:20 ,大小:17.72KB ,
资源ID:11337885      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11337885.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(RSA 公钥算法Java代码带界面.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

RSA 公钥算法Java代码带界面.docx

1、RSA 公钥算法Java代码带界面RSA公钥加密算法代码package .rsa.service;public class UnPrimeException extends Exception public UnPrimeException() public UnPrimeException(String message) super(message); public UnPrimeException(Throwable cause) super(cause); public UnPrimeException(String message, Throwable cause) super(mes

2、sage, cause); -package .rsa.service;public interface DataInfo public MyData sendData(long p, long q, long public_key, long deprime)throws UnPrimeException;-package .rsa.service;public class DataDeal implements DataInfo Override public MyData sendData(long p, long q, long public_key, long deprime) th

3、rows UnPrimeException MyData data ; if (!this.primeNumber(q)|!this.primeNumber(q) throw new UnPrimeException(非素数,请重新输入!) ; else if(deprime = this.getF(p,q) | (this.gcd(this.getF(p, q),deprime)!=1) throw new UnPrimeException(输入的公钥不符合条件!) ; else data = new MyData(p, q,public_key, deprime) ; return dat

4、a ; /判断是否为素数 public boolean primeNumber(long t) long k=0; k=(long)Math.sqrt(double)t); boolean flag=true; outer:for(int i=2;i=k;i+) if(t%i)=0) flag = false; break outer; return flag; private long gcd(long a, long b)/最大公约数 long gcd; if(b=0)gcd=a; else gcd=gcd(b,a%b); return gcd; private long getF(lon

5、g p, long q) return (p - 1)*(q -1) ; -package .rsa.service;public class MyData private long p; private long q; private long public_key ; private long deprime ; public MyData() super(); public MyData(long p, long q, long public_key, long deprime) super(); this.p = p; this.q = q; this.public_key = pub

6、lic_key; this.deprime = deprime; public long getP() return p; public void setP(long p) this.p = p; public long getQ() return q; public void setQ(long q) this.q = q; public long getDeprime() return deprime; public void setDeprime(long deprime) this.deprime = deprime; public long getPublic_key() retur

7、n public_key; public void setPublic_key(long public_key) this.public_key = public_key; public boolean toPrime()/判断最大公约数是否为1 if(this.gcd(p, q) != 1) return false ; return true ; /求最大公约数 public long gcd(long a, long b) long gcd; if(b=0)gcd=a; else gcd=gcd(b,a%b); return gcd; public long getN() return

8、p*q ; public long getF() return (p - 1)*(q -1) ; public long colum(long y,long n,long key) /加密/解密 long mul; if(key=1)mul=y%n; else mul=y*this.colum(y,n,key-1)%n; return mul; /计算得到密匙 public long getPrivate_key() long f = this.getF() ; long private_key = 1; long value=1; for(long i=1;i+) value=i*f+1;

9、if(value%this.public_key=0)& (value/this.public_key f) private_key=value/this.public_key; break ; return private_key ; /得到密文 public long getMyPrime() return this.colum(this.deprime, this.getN(), this.public_key) ; public String getStrPrime() return Long.toString(this.getMyPrime() ; /得到解密的文件 public l

10、ong getMyDeprime() return this.colum(this.getMyPrime(), this.getN(), this.getPrivate_key() ; public String getStrDeprime() return Long.toString(this.getMyDeprime() ; -package .rsa.frame;import java.awt.BorderLayout;import java.awt.Component;import java.awt.FlowLayout;import java.awt.GridLayout;impor

11、t java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPassword

12、Field;import javax.swing.JTextField;import javax.swing.border.EmptyBorder;public class SenderFrame extends JFrame /* * */ private static final long serialVersionUID = 1L; public SenderFrame() init() ; public void init() setTitle(Sender); setSize(300, 220); setContentPane(createContentPane(); addWind

13、owListener(new WindowAdapter() public void windowClosing(WindowEvent e) client.exit(SenderFrame.this) ; ); private JPanel createContentPane() JPanel p = new JPanel(new BorderLayout(); p.add(BorderLayout.NORTH, new JLabel(发送数据, JLabel.CENTER); p.add(BorderLayout.CENTER, createCenterPane(); p.add(Bord

14、erLayout.SOUTH, createBtnPane(); p.setBorder(new EmptyBorder(6,6,6,6); return p; private JPanel createCenterPane() JPanel p= new JPanel(new BorderLayout(); p.add(BorderLayout.NORTH, createIdPwdPane(); p.setBorder(new EmptyBorder(6,6,6,6); return p; private JPanel createIdPwdPane() JPanel p= new JPan

15、el(new GridLayout(2, 2, 0, 6); p.add(createP(); p.add(createQ() ; p.add(createPublic_key() ; p.add(createPrime(); return p; private JPanel createP() JPanel p = new JPanel(new BorderLayout(5,0); p.add(BorderLayout.WEST, new JLabel(素数p:); idP = new JPasswordField(); idP.enableInputMethods(true); p.add

16、(BorderLayout.CENTER, idP); return p; private JPanel createQ() JPanel p = new JPanel(new BorderLayout(5,0); p.add(BorderLayout.WEST, new JLabel(素数q:); idQ = new JPasswordField(); idQ.enableInputMethods(true); p.add(BorderLayout.CENTER, idQ); return p; private JPanel createPublic_key() JPanel p = new

17、 JPanel(new BorderLayout(5,0); p.add(BorderLayout.WEST, new JLabel(公 钥:); public_key = new JTextField(); p.add(BorderLayout.CENTER, public_key); return p; private JPanel createPrime() JPanel p = new JPanel(new BorderLayout(5,0); p.add(BorderLayout.WEST, new JLabel(明 文:); prime = new JTextField(); p.

18、add(BorderLayout.CENTER, prime); return p; private JPanel createBtnPane() JPanel p= new JPanel(new FlowLayout(); JButton login = new JButton(发送); JButton cancel = new JButton(取消); p.add(login); p.add(cancel); getRootPane().setDefaultButton(login); login.addActionListener(new ActionListener() public

19、void actionPerformed(ActionEvent e) client.send() ; ); cancel.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) client.exit(SenderFrame.this) ; ); return p; private Client client ; public void setClient(Client client) this.client = client ; private JTextField public_k

20、ey ; private JTextField prime; private JPasswordField idP; private JPasswordField idQ; public long getP() char str = idP.getPassword(); String s = new String(str); return Integer.parseInt(s); public long getQ() char q = idQ.getPassword(); String s = new String(q); return Integer.parseInt(s) ; public

21、 long getPrime() String str = prime.getText(); return Integer.parseInt(str); public long getPublic_key() String str = public_key.getText(); return Integer.parseInt(str); -package .rsa.frame;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.Actio

22、nEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;public class ReceiverFrame extends JFrame /

23、* * */ private static final long serialVersionUID = 1L; public ReceiverFrame() this.shows() ; public void shows() setTitle(Receiver); setSize(300, 180); setContentPane(createContentPane(); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0) ; ); private JPan

24、el createContentPane() JPanel p = new JPanel(new BorderLayout(); p.add(BorderLayout.NORTH, new JLabel(接收数据, JLabel.CENTER); p.add(BorderLayout.CENTER, createCenterPane(); p.add(BorderLayout.SOUTH, createBtnPane(); p.setBorder(new EmptyBorder(6,6,6,6); return p; private JPanel createCenterPane() JPan

25、el p= new JPanel(new BorderLayout(); p.add(BorderLayout.NORTH, createCipPane(); p.setBorder(new EmptyBorder(6,6,6,6); return p; private JPanel createCipPane() JPanel p= new JPanel(new GridLayout(2, 1, 0, 6); p.add(createIdPane(); p.add(createPwdPane(); return p; private JPanel createIdPane() JPanel

26、p = new JPanel(new BorderLayout(5,0); p.add(BorderLayout.WEST, new JLabel(密文:); cipField= new JLabel(); p.add(BorderLayout.CENTER, cipField); return p; private JPanel createPwdPane() JPanel p = new JPanel(new BorderLayout(5,0); p.add(BorderLayout.WEST, new JLabel(解密:); decipField = new JLabel(); p.add(BorderLayout.CENTER, decipField); return p; private JPanel createBtnPane() JPanel p= new JPanel(new FlowLayout(); JButton button1 = new JButton(解密); JButton button = new JButton(确认); p.add(button1) ; p.add(button); getRootPane().setDefaultButton(button);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1