Pastebin

Paste #204:

< previous paste - next paste>

Pasted by KimI

Download View as text

/*
 *  This program signs a small access right certificate using
 *  SHA1withDSA.
 */
public class DoSign {

    public static void main(String[] args) throws Exception {
    KeyManager[] xkm = null;
    KeyManagerFactory kmf;
    KeyStore ks;

    if(args.length != 1) {
        System.out.println("Usage: java DoSign <ID:rights string>");
        System.exit(-1);
    } else
        System.out.println("signing: " + args[0]);

    /*
     *  Open the server keystore and get server public key for signing.
     */
    char[] passphrase = "idsids".toCharArray();
    kmf = KeyManagerFactory.getInstance("SunX509");
    ks = KeyStore.getInstance("JKS");
    ks.load(new FileInputStream("ServerStore"), passphrase);
    kmf.init(ks, passphrase);
    xkm = kmf.getKeyManagers();
    X509KeyManager xxkm = (X509KeyManager) xkm[0];
    PrivateKey pk = xxkm.getPrivateKey("server");

    /*
     *  Now sign the string given as argument.
     */
    Signature dsa = Signature.getInstance("SHA1withDSA");
    dsa.initSign(pk);
    dsa.update(args[0].getBytes());
    byte[] signature = dsa.sign();
    /* Convert signature to hex using BigInteger */
    BigInteger bi = new BigInteger(signature);
    String txtSignature = bi.toString(16);
    if (txtSignature.length() % 2 != 0) {
        // Pad with 0
        txtSignature = "0"+txtSignature;
    }
    System.out.println(args[0] + ":" + txtSignature);
    }
}

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.