http://www.docin.com/p-5312518.html
我自己写了个DH秘钥的demo代码, 以前加密用过AES的加密,全套代码写下来太费时间又没技术含量。
如果你需要AES的加密代码可以留个邮箱给我。
public class Test1 {public static final int P=30//公开的大家都知道的
public static final int G=9//公开的大家都知道的
public static void main(String[] args) {
A x = new A()
int one = x.getV()
//分割 A 代表A这边的系统加密 one 代表是给别人的值
B y = new B()
int two = y.getV()
//B 代表另外一边加密 two 代表是给别人的值
System.out.println(x.getKey(two))
System.out.println(y.getKey(one))
}
}
class A{
private int a//自己的私有密值,不会告诉任何人
public A() {
Random r = new Random(200)
a=r.nextInt()
}
public int getV(){
return (Test1.G^a)%Test1.P
}
public int getKey(int v){
return (v^a)%Test1.P
}
}
class B{
private int b//自己的私有密值,不会告诉任何人
public B() {
Random r = new Random(200)
b=r.nextInt()
}
public int getV(){
return (Test1.G^b)%Test1.P
}
public int getKey(int v){
return (v^b)%Test1.P
}
}