Search in sources :

Example 1 with SecretDecoderRing

use of org.mozilla.jss.crypto.SecretDecoderRing in project jss by dogtagpki.

the class SDR method main.

public static void main(String[] args) {
    try {
        String cmd = args[0];
        String infile = args[1];
        String outfile = args[2];
        CryptoManager cm = CryptoManager.getInstance();
        CryptoToken token = cm.getInternalKeyStorageToken();
        token.login(new ConsolePasswordCallback());
        SecretDecoderRing sdr = new SecretDecoderRing();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        int numread;
        byte[] data = new byte[1024];
        try (FileInputStream fis = new FileInputStream(infile)) {
            while ((numread = fis.read(data)) != -1) {
                bos.write(data, 0, numread);
            }
        }
        byte[] inputBytes = bos.toByteArray();
        byte[] outputBytes;
        if (cmd.equalsIgnoreCase("encrypt")) {
            outputBytes = sdr.encrypt(inputBytes);
        } else {
            outputBytes = sdr.decrypt(inputBytes);
        }
        try (FileOutputStream fos = new FileOutputStream(outfile)) {
            fos.write(outputBytes);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.exit(0);
}
Also used : SecretDecoderRing(org.mozilla.jss.crypto.SecretDecoderRing) CryptoToken(org.mozilla.jss.crypto.CryptoToken) FileOutputStream(java.io.FileOutputStream) CryptoManager(org.mozilla.jss.CryptoManager) ConsolePasswordCallback(org.mozilla.jss.util.ConsolePasswordCallback) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 CryptoManager (org.mozilla.jss.CryptoManager)1 CryptoToken (org.mozilla.jss.crypto.CryptoToken)1 SecretDecoderRing (org.mozilla.jss.crypto.SecretDecoderRing)1 ConsolePasswordCallback (org.mozilla.jss.util.ConsolePasswordCallback)1