Source Code : Signing a Java Object
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Signing a Java Object
import java.io.Serializable;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignedObject;
public class Main {
public static void main(String[] argv) throws Exception {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey privateKey = keypair.getPrivate();
PublicKey publicKey = keypair.getPublic();
Serializable o = new MyClass();
Signature sig = Signature.getInstance(privateKey.getAlgorithm());
SignedObject so = new SignedObject(o, privateKey, sig);
sig = Signature.getInstance(publicKey.getAlgorithm());
boolean b = so.verify(publicKey, sig);
o = (MyClass) so.getObject();
}
}
class MyClass implements Serializable {
String s = "my string";
int i = 123;
}
Thank with us