m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/KeyGenerator.java
blob: 85812808a33515d1f293e54c7dc2a652bbbea3a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package pl.edu.mimuw.cloudatlas;

import java.security.*;

public class KeyGenerator {
    private final static int NUM_KEY_BITS = 1024;
    private final static String ENCRYPTION_ALGORITHM = "RSA";

    // TODO
    // TODO read key values from files
    // TODO gradlew
    private static void printKeyToFile(byte[] keyValue, String fileName) {

    }

    private static void generateKeys() throws NoSuchAlgorithmException {
        PublicKey publicKey;
        PrivateKey privateKey;

        KeyPairGenerator keyGenerator =
                KeyPairGenerator.getInstance(ENCRYPTION_ALGORITHM);
        keyGenerator.initialize(NUM_KEY_BITS);
        KeyPair keyPair = keyGenerator.generateKeyPair();

        privateKey = keyPair.getPrivate();
        printKeyToFile(privateKey.getEncoded(), "query_signer");
        publicKey = keyPair.getPublic();
        printKeyToFile(publicKey.getEncoded(), "query_signer.pub");
    }

    public static void main() {
        try {
            generateKeys();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
}