Example usage for org.bouncycastle.bcpg S2K SALTED_AND_ITERATED

List of usage examples for org.bouncycastle.bcpg S2K SALTED_AND_ITERATED

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg S2K SALTED_AND_ITERATED.

Prototype

int SALTED_AND_ITERATED

To view the source code for org.bouncycastle.bcpg S2K SALTED_AND_ITERATED.

Click Source Link

Document

Salted and iterated key generation.

Usage

From source file:genkeys.java

License:Open Source License

public static void main(String[] args) {
    Security.addProvider(new BouncyCastleProvider());
    Random rand = new Random();

    for (String keyType : keyTypes) {
        System.out.print("Generating " + keyType + " keys... ");
        for (int keyLength : keyLengths) {

            if (keyType == "DSA" && keyLength > 1024) {
                continue;
            }/*from  w  w w  .  ja v a 2s  .c  om*/

            System.out.print(keyLength);
            System.out.print(" ");

            KeyPair kp;
            try {
                kp = generatePair(keyType, keyLength);
            } catch (Exception e) {
                System.err.println("Error generating key: " + e.getMessage());
                continue;
            }

            for (int hash : hashAlgorithms) {
                String dir = String.format("%s/%s/%d/%s", keyDir, keyType, keyLength,
                        hashNames[hash].toLowerCase());
                new File(dir).mkdirs();

                for (int cipher : ciphers) {
                    boolean[] truthValues = { true, false };
                    for (boolean useSHA1 : truthValues) {
                        FileOutputStream out;
                        boolean armor = rand.nextBoolean();
                        try {
                            out = new FileOutputStream(
                                    String.format("%s/%s%s.%s", dir, cipherNames[cipher].toLowerCase(),
                                            (useSHA1 ? "_sha1" : ""), (armor ? "asc" : "pgp")));
                            exportSecretKey(out, kp, cipher, S2K.SALTED_AND_ITERATED, hash, useSHA1,
                                    password(rand), armor);
                        } catch (Exception e) {
                            System.err.println("Error exporting key: " + e.getMessage());
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        System.out.println();
    }
}