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);
}
Aggregations