Code example for PrivateKey

Methods: getEncoded

0
      KeyPair keyPair = generator.genKeyPair();
      PublicKey publicKey = keyPair.getPublic();
      PrivateKey privateKey = keyPair.getPrivate();
       
      saveRSAKeyToFile( PUBLIC_KEY_FILE, publicKey.getEncoded() );
      saveRSAKeyToFile( PRIVATE_KEY_FILE, privateKey.getEncoded() );
      return keyPair;
    } 
    catch ( Exception e )
    { 
      e.printStackTrace();
    } 
    return null; 
  } 
   
  /** 
   * Method to store a public or a private RSA key bytes 
   *  
   * @param file 
   *          the file to save the key into 
   * @param bytes