public static CryptoImplementation getCryptoImplementation(int id) { return CryptoFactory.getInstance(id); }
public List<CryptoImplementation> getCryptoImplementations() { return CryptoFactory.getInstances(); }
public synchronized static List<CryptoImplementation> getInstances() { if (instances == null) init(); return instances; }
for (CryptoImplementation cryptoImpl: CryptoFactory.getInstances()) { int base64Length = cryptoImpl.getBase64PublicKeyPairLength(); // length of an email destination with this CryptoImplementation
/** * Creates an <code>EncryptedEmailPacket</code> from raw datagram data. * To read the encrypted parts of the packet, {@link #decrypt(EmailIdentity)} must be called first. * @param data * @throws InvalidAlgorithmParameterException * @throws NoSuchAlgorithmException */ public EncryptedEmailPacket(byte[] data) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { super(data); ByteBuffer buffer = ByteBuffer.wrap(data, HEADER_LENGTH, data.length-HEADER_LENGTH); dhtKey = readHash(buffer); storeTime = buffer.getInt() * 1000L; delVerificationHash = readHash(buffer); byte cryptoImplId = buffer.get(); cryptoImpl = CryptoFactory.getInstance(cryptoImplId); int encryptedLength = buffer.getShort() & 0xFFFF; // length of the encrypted part of the packet encryptedData = new byte[encryptedLength]; buffer.get(encryptedData); }
public synchronized static CryptoImplementation getInstance(int id) { if (instances == null) init(); for (CryptoImplementation instance: instances) if (instance.getId() == id) return instance; return null; }
public EmailDestination(byte[] bytes) throws GeneralSecurityException { // find the crypto implementation for this key length for (CryptoImplementation cryptoImpl: CryptoFactory.getInstances()) { int byteArrayLength = cryptoImpl.getByteArrayPublicKeyPairLength(); // length of an email destination that uses this CryptoImplementation if (bytes.length == byteArrayLength) this.cryptoImpl = cryptoImpl; } if (cryptoImpl == null) throw new InvalidKeyException("Not a valid Email Destination: " + Arrays.toString(bytes)); PublicKeyPair keyPair = cryptoImpl.createPublicKeyPair(bytes); publicEncryptionKey = keyPair.encryptionKey; publicSigningKey = keyPair.signingKey; }
return false; CryptoImplementation cryptoImpl = CryptoFactory.getInstance(cryptoImplId);
/** * @param address A string containing a valid base64-encoded Email Destination * @throws GeneralSecurityException If <code>address</code> doesn't contain a valid Email Destination */ public EmailDestination(String address) throws GeneralSecurityException { String base64Key = extractBase64Dest(address); if (base64Key == null) throw new GeneralSecurityException("No Email Destination found in string: <" + address + ">"); // find the crypto implementation for this key length for (CryptoImplementation cryptoImpl: CryptoFactory.getInstances()) { int base64Length = cryptoImpl.getBase64PublicKeyPairLength(); // length of an email destination that uses this CryptoImplementation if (base64Key.length() == base64Length) this.cryptoImpl = cryptoImpl; } if (cryptoImpl == null) throw new InvalidKeyException("Not a valid Email Destination: <" + base64Key + ">"); PublicKeyPair keyPair = cryptoImpl.createPublicKeyPair(base64Key); publicEncryptionKey = keyPair.encryptionKey; publicSigningKey = keyPair.signingKey; }
CryptoImplementation cryptoImpl = CryptoFactory.getInstance(cryptoImplId); if (cryptoImpl == null) { log.error("Invalid ID number for CryptoImplementation: " + cryptoImplId);
/** * Creates a <code>EmailIdentity</code> from a Base64-encoded string. * The format can be any format supported by one of the {@link CryptoImplementation}s; * the length of the string must match {@link CryptoImplementation#getBase64CompleteKeySetLength()}. * @param base64Key * @throws GeneralSecurityException */ public EmailIdentity(String base64Key) throws GeneralSecurityException { // find the crypto implementation for this key length for (CryptoImplementation cryptoImpl: CryptoFactory.getInstances()) { int base64Length = cryptoImpl.getBase64CompleteKeySetLength(); // length of an email identity with this CryptoImplementation if (base64Key.length() == base64Length) { this.cryptoImpl = cryptoImpl; break; } } if (cryptoImpl == null) throw new InvalidKeyException("Not a valid Email Identity, no CryptoImplementation (out of " + CryptoFactory.getInstances().size() + ") matches length " + base64Key.length() + ": <" + base64Key + ">"); String base64PublicKeys = base64Key.substring(0, cryptoImpl.getBase64PublicKeyPairLength()); // the two private keys start after the two public keys PublicKeyPair publicKeys = cryptoImpl.createPublicKeyPair(base64PublicKeys); String base64PrivateKeys = base64Key.substring(cryptoImpl.getBase64PublicKeyPairLength()); // the two private keys start after the two public keys PrivateKeyPair privateKeys = cryptoImpl.createPrivateKeyPair(base64PrivateKeys); publicEncryptionKey = publicKeys.encryptionKey; privateEncryptionKey = privateKeys.encryptionKey; publicSigningKey = publicKeys.signingKey; privateSigningKey = privateKeys.signingKey; identityConfig = new IdentityConfigImpl(); }