/** * Creates a random <code>EmailIdentity</code>. * @param cryptoImpl * @param vanityPrefix Base64 chars that the Email Destination should start with; <code>null</code> or an empty string for no vanity Destination. * @throws GeneralSecurityException * @throws IllegalDestinationParametersException if <code>cryptoImpl</code> and <code>vanityPrefix</code> aren't compatible */ public EmailIdentity(CryptoImplementation cryptoImpl, String vanityPrefix) throws GeneralSecurityException, IllegalDestinationParametersException { super(); this.cryptoImpl = cryptoImpl; if ("".equals(vanityPrefix)) vanityPrefix = null; if (vanityPrefix!=null && !cryptoImpl.getBase64InitialCharacters().contains(vanityPrefix.substring(0, 1))) { throw new IllegalDestinationParametersException(vanityPrefix.charAt(0), cryptoImpl.getBase64InitialCharacters()); } KeyPair encryptionKeys; do { encryptionKeys = cryptoImpl.generateEncryptionKeyPair(); } while (vanityPrefix!=null && !cryptoImpl.encryptionKeyToBase64(encryptionKeys.getPublic()).startsWith(vanityPrefix)); KeyPair signingKeys = cryptoImpl.generateSigningKeyPair(); publicEncryptionKey = encryptionKeys.getPublic(); privateEncryptionKey = encryptionKeys.getPrivate(); publicSigningKey = signingKeys.getPublic(); privateSigningKey = signingKeys.getPrivate(); identityConfig = new IdentityConfigImpl(); }