@Override public byte[] decrypt(final byte[] ciphertext, final byte[] associatedData) throws GeneralSecurityException { if (ciphertext.length > CryptoFormat.NON_RAW_PREFIX_SIZE) { byte[] prefix = Arrays.copyOfRange(ciphertext, 0, CryptoFormat.NON_RAW_PREFIX_SIZE); byte[] ciphertextNoPrefix = Arrays.copyOfRange(ciphertext, CryptoFormat.NON_RAW_PREFIX_SIZE, ciphertext.length); List<PrimitiveSet.Entry<Aead>> entries = pset.getPrimitive(prefix); for (PrimitiveSet.Entry<Aead> entry : entries) { try { return entry.getPrimitive().decrypt(ciphertextNoPrefix, associatedData); } catch (GeneralSecurityException e) { logger.info("ciphertext prefix matches a key, but cannot decrypt: " + e.toString()); continue; } } } // Let's try all RAW keys. List<PrimitiveSet.Entry<Aead>> entries = pset.getRawPrimitives(); for (PrimitiveSet.Entry<Aead> entry : entries) { try { return entry.getPrimitive().decrypt(ciphertext, associatedData); } catch (GeneralSecurityException e) { continue; } } // nothing works. throw new GeneralSecurityException("decryption failed"); } };
@Override public byte[] decrypt(final byte[] ciphertext, final byte[] contextInfo) throws GeneralSecurityException { if (ciphertext.length > CryptoFormat.NON_RAW_PREFIX_SIZE) { byte[] prefix = Arrays.copyOfRange(ciphertext, 0, CryptoFormat.NON_RAW_PREFIX_SIZE); byte[] ciphertextNoPrefix = Arrays.copyOfRange(ciphertext, CryptoFormat.NON_RAW_PREFIX_SIZE, ciphertext.length); List<PrimitiveSet.Entry<HybridDecrypt>> entries = primitives.getPrimitive(prefix); for (PrimitiveSet.Entry<HybridDecrypt> entry : entries) { try { return entry.getPrimitive().decrypt(ciphertextNoPrefix, contextInfo); } catch (GeneralSecurityException e) { logger.info("ciphertext prefix matches a key, but cannot decrypt: " + e.toString()); continue; } } } // Let's try all RAW keys. List<PrimitiveSet.Entry<HybridDecrypt>> entries = primitives.getRawPrimitives(); for (PrimitiveSet.Entry<HybridDecrypt> entry : entries) { try { return entry.getPrimitive().decrypt(ciphertext, contextInfo); } catch (GeneralSecurityException e) { continue; } } // nothing works. throw new GeneralSecurityException("decryption failed"); } };
List<PrimitiveSet.Entry<DeterministicAead>> entries = primitives.getRawPrimitives(); for (PrimitiveSet.Entry<DeterministicAead> entry : entries) { try {
List<PrimitiveSet.Entry<StreamingAead>> entries; try { entries = primitives.getRawPrimitives(); } catch (GeneralSecurityException e) { throw new IOException("Keyset failure: ", e);
List<PrimitiveSet.Entry<StreamingAead>> entries; try { entries = primitives.getRawPrimitives(); } catch (GeneralSecurityException e) { throw new IOException("Keyset failure: ", e);
List<PrimitiveSet.Entry<StreamingAead>> entries; try { entries = primitives.getRawPrimitives(); } catch (GeneralSecurityException e) { throw new IOException("Keyset failure: ", e);
entries = primitives.getRawPrimitives(); for (PrimitiveSet.Entry<Mac> entry : entries) { try {
entries = primitives.getRawPrimitives(); for (PrimitiveSet.Entry<PublicKeyVerify> entry : entries) { try {