-
Notifications
You must be signed in to change notification settings - Fork 0
/
DigitalSignature_Demo.java
39 lines (30 loc) · 1.14 KB
/
DigitalSignature_Demo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Digital Signature Scheme demonstration
*
*/
import java.math.BigInteger;
import DigitalSignature.DecryptedTransport;
import DigitalSignature.EncryptedTransport;
import rsa.*;
public class DigitalSignature_Demo {
public static void main(String[] args) {
// Message
String message = "1010101011100101";
// Generating RSA Private Key
BigInteger p = new BigInteger("221671");
BigInteger q = new BigInteger("228989");
PrivateKey privateKey = new PrivateKey(p, q);
// AES Secret Key
String K = "1100101011110001";
// Bob sends a packet
EncryptedTransport sentPacket = new EncryptedTransport(message, K, privateKey);
// Alice recieves a packet
DecryptedTransport recievedPacket = new DecryptedTransport(sentPacket);
// Recieving
BigInteger z = new BigInteger("" + recievedPacket.getRsaSignature());
// Testing
System.out.println(message + " = " + recievedPacket.getDecrypted());
System.out.println(z + " = " + sentPacket.getHash());
System.out.println("Are the hashes same? " + recievedPacket.isValid());
}
}