Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. public void generujKlucze(String mail,char[] pas) {
  2.     try {                
  3.        
  4.       final KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM);
  5.       keyGen.initialize(1024);
  6.       final KeyPair key = keyGen.generateKeyPair();
  7.  
  8.       File privateKeyFile = new File(PRIVATE_KEY_FILE+mail+".priv");
  9.       File publicKeyFile = new File(PUBLIC_KEY_FILE+mail+".publ");
  10.  
  11.       // Create files to store public and private key
  12.       if (privateKeyFile.getParentFile() != null) {
  13.         privateKeyFile.getParentFile().mkdirs();
  14.       }
  15.       privateKeyFile.createNewFile();
  16.  
  17.       if (publicKeyFile.getParentFile() != null) {
  18.         publicKeyFile.getParentFile().mkdirs();
  19.       }
  20.       publicKeyFile.createNewFile();
  21.  
  22.       // Saving the Public key in a file
  23.       ObjectOutputStream publicKeyOS = new ObjectOutputStream(
  24.           new FileOutputStream(publicKeyFile));
  25.       publicKeyOS.writeObject(key.getPublic());
  26.       publicKeyOS.close();
  27.  
  28.       // Saving the Private key in a file
  29.       ObjectOutputStream privateKeyOS = new ObjectOutputStream(
  30.           new FileOutputStream(privateKeyFile));
  31.       privateKeyOS.writeObject(key.getPrivate());
  32.       privateKeyOS.close();
  33.     } catch (Exception e) {
  34.       e.printStackTrace();
  35.     }
  36.  
  37.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement