Example usage for java.security SignedObject verify

List of usage examples for java.security SignedObject verify

Introduction

In this page you can find the example usage for java.security SignedObject verify.

Prototype

public boolean verify(PublicKey verificationKey, Signature verificationEngine)
        throws InvalidKeyException, SignatureException 

Source Link

Document

Verifies that the signature in this SignedObject is the valid signature for the object stored inside, with the given verification key, using the designated verification engine.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String alg = "DSA";
    KeyPairGenerator kg = KeyPairGenerator.getInstance(alg);
    KeyPair keyPair = kg.genKeyPair();

    Vector v = new Vector();
    v.add("This is a test!");
    Signature sign = Signature.getInstance(alg);
    SignedObject so = new SignedObject(v, keyPair.getPrivate(), sign);
    System.out.println(so.verify(keyPair.getPublic(), sign));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
    keyGen.initialize(1024);//w  w  w  . j a v a 2 s  .  c o  m
    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();
}

From source file:bftsmart.tom.core.TOMLayer.java

/**
 * Verifies the signature of a signed object
 * @param so Signed object to be verified
 * @param sender Replica id that supposedly signed this object
 * @return True if the signature is valid, false otherwise
 *///from  w w  w .  j a  va  2  s .  c  o m
public boolean verifySignature(SignedObject so, int sender) {
    try {
        return so.verify(controller.getStaticConf().getRSAPublicKey(sender), engine);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}