FileDocCategorySizeDatePackage
NotaryPublic.javaAPI DocExample1725Tue Dec 12 18:58:42 GMT 2000bingo.game

NotaryPublic

public class NotaryPublic extends Object

Fields Summary
private PrivateKey
priv
private PublicKey
pub
Constructors Summary
NotaryPublic()


     
        KeyPair pair = null;
        try {
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
            keyGen.initialize(1024, new SecureRandom());
            pair = keyGen.generateKeyPair();
        } catch (Exception e) {
	    ErrorMessages.error("Cannot sign cards. Continuing anyway.");
        }
	priv = pair.getPrivate();
	pub = pair.getPublic();
    
Methods Summary
voidsignTheCard(Card c, int gameNumber)

        Signature dsa = Signature.getInstance("SHA/DSA");
	byte[] values = new byte[Card.SIZE*Card.SIZE+1];

        dsa.initSign(priv);

        for (int i = 0; i < Card.SIZE; i++)
            for (int j = 0; j < Card.SIZE; j ++)
		values[Card.SIZE*i + j] = (byte)c.boardValues[i][j].number;
	values[values.length-1] = (byte)gameNumber;

	dsa.update(values);
	c.setSignature(dsa.sign());
    
booleanverifyTheSignature(Card c, int gameNumber)

        try {
            Signature dsa = Signature.getInstance("SHA/DSA");
	    byte[] values = new byte[Card.SIZE*Card.SIZE+1];

            dsa.initVerify(pub);

            for (int i = 0; i < Card.SIZE; i ++)
                for (int j = 0; j < Card.SIZE; j ++)
                    values[Card.SIZE*i + j] = (byte)c.boardValues[i][j].number;
	    values[values.length-1] = (byte)gameNumber;

	    dsa.update(values);
            return dsa.verify(c.getSignature());
        } catch (Exception e) {
            return false;
        }