Esempio n. 1
0
  /**
   * Generate the RSA key pairs for encrypting the DES file key
   *
   * @throws InvalidKeySpecException
   */
  private void genRSAKeys() throws InvalidKeySpecException {
    try {
      KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");

      SecureRandom random = new SecureRandom();
      String seed = ((Long) System.currentTimeMillis()).toString();
      random.setSeed(seed.getBytes());
      keygen.initialize(1024, random);

      KeyPair kp = keygen.generateKeyPair();
      publicKey = (RSAPublicKey) kp.getPublic();
      privateKey = (RSAPrivateKey) kp.getPrivate();

      // System.out.println("RSA public key: " + publicKey);
      // System.out.println("RSA private key: " + privateKey);

    } catch (NoSuchAlgorithmException e) {
      System.out.println("Failed to generate RSA key pairs!\n" + e.toString());
    }
  }