Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void generujKlucze(String mail,char[] pas) {
- try {
- final KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM);
- keyGen.initialize(1024);
- final KeyPair key = keyGen.generateKeyPair();
- File privateKeyFile = new File(PRIVATE_KEY_FILE+mail+".priv");
- File publicKeyFile = new File(PUBLIC_KEY_FILE+mail+".publ");
- // Create files to store public and private key
- if (privateKeyFile.getParentFile() != null) {
- privateKeyFile.getParentFile().mkdirs();
- }
- privateKeyFile.createNewFile();
- if (publicKeyFile.getParentFile() != null) {
- publicKeyFile.getParentFile().mkdirs();
- }
- publicKeyFile.createNewFile();
- // Saving the Public key in a file
- ObjectOutputStream publicKeyOS = new ObjectOutputStream(
- new FileOutputStream(publicKeyFile));
- publicKeyOS.writeObject(key.getPublic());
- publicKeyOS.close();
- // Saving the Private key in a file
- ObjectOutputStream privateKeyOS = new ObjectOutputStream(
- new FileOutputStream(privateKeyFile));
- privateKeyOS.writeObject(key.getPrivate());
- privateKeyOS.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement