/** * Sets the chunk size of the data stream. * Needs to be set before the data stream is requested. * When not set, the implementation uses method specific default values * * @param chunkSize the chunk size, i.e. the block size with the same encryption key */ public void setChunkSize(int chunkSize) { throw new EncryptedDocumentException("this decryptor doesn't support changing the chunk size"); }
/** * Sets the chunk size of the data stream. * Needs to be set before the data stream is requested. * When not set, the implementation uses method specific default values * * @param chunkSize the chunk size, i.e. the block size with the same encryption key */ public void setChunkSize(int chunkSize) { throw new EncryptedDocumentException("this decryptor doesn't support changing the chunk size"); }
/** * Initializes a cipher object for a given block index for encryption * * @param cipher may be null, otherwise the given instance is reset to the new block index * @param block the block index, e.g. the persist/slide id (hslf) * @return a new cipher object, if cipher was null, otherwise the reinitialized cipher * @throws GeneralSecurityException if the cipher can't be initialized */ public Cipher initCipherForBlock(Cipher cipher, int block) throws GeneralSecurityException { throw new EncryptedDocumentException("this decryptor doesn't support initCipherForBlock"); }
@Override public void write(byte[] b, int off, int len) { try { cipher.update(b, off, len, b, off); super.write(b, off, len); } catch (Exception e) { throw new EncryptedDocumentException(e); } }
@Override public void write(int b) { try { oneByte[0] = (byte)b; cipher.update(oneByte, 0, 1, oneByte, 0); super.write(oneByte); } catch (Exception e) { throw new EncryptedDocumentException(e); } }
public static HashAlgorithm fromEcmaId(int ecmaId) { for (HashAlgorithm ha : values()) { if (ha.ecmaId == ecmaId) { return ha; } } throw new EncryptedDocumentException("hash algorithm not found"); }
public static Decryptor getInstance(EncryptionInfo info) { Decryptor d = info.getDecryptor(); if (d == null) { throw new EncryptedDocumentException("Unsupported version"); } return d; }
private FilePassRecord(FilePassRecord other) { encryptionType = other.encryptionType; try { encryptionInfo = other.encryptionInfo.clone(); } catch (CloneNotSupportedException e) { throw new EncryptedDocumentException(e); } }
public static CipherAlgorithm fromEcmaId(int ecmaId) { for (CipherAlgorithm ca : CipherAlgorithm.values()) { if (ca.ecmaId == ecmaId) return ca; } throw new EncryptedDocumentException("cipher algorithm " + ecmaId + " not found"); }
public static HashAlgorithm fromString(String string) { for (HashAlgorithm ha : values()) { if (ha.ecmaString.equalsIgnoreCase(string) || ha.jceId.equalsIgnoreCase(string)) { return ha; } } throw new EncryptedDocumentException("hash algorithm not found"); } }
public static MessageDigest getMessageDigest(HashAlgorithm hashAlgorithm) { try { if (hashAlgorithm.needsBouncyCastle) { registerBouncyCastle(); return MessageDigest.getInstance(hashAlgorithm.jceId, "BC"); } else { return MessageDigest.getInstance(hashAlgorithm.jceId); } } catch (GeneralSecurityException e) { throw new EncryptedDocumentException("hash algo not supported", e); } }
public static CipherProvider fromEcmaId(int ecmaId) { for (CipherProvider cp : CipherProvider.values()) { if (cp.ecmaId == ecmaId) return cp; } throw new EncryptedDocumentException("cipher provider not found"); }
public static HashAlgorithm fromEcmaId(String ecmaString) { for (HashAlgorithm ha : values()) { if (ha.ecmaString.equals(ecmaString)) { return ha; } } throw new EncryptedDocumentException("hash algorithm not found"); }
protected static EncryptionDocument parseDescriptor(InputStream descriptor) { try { return EncryptionDocument.Factory.parse(descriptor, DEFAULT_XML_OPTIONS); } catch (Exception e) { throw new EncryptedDocumentException("Unable to parse encryption descriptor", e); } } }
@Override protected void setSalt(byte salt[]) { if (salt == null || salt.length != 16) { throw new EncryptedDocumentException("invalid verifier salt"); } super.setSalt(salt); }
public static Mac getMac(HashAlgorithm hashAlgorithm) { try { if (hashAlgorithm.needsBouncyCastle) { registerBouncyCastle(); return Mac.getInstance(hashAlgorithm.jceHmacId, "BC"); } else { return Mac.getInstance(hashAlgorithm.jceHmacId); } } catch (GeneralSecurityException e) { throw new EncryptedDocumentException("hmac algo not supported", e); } }
public static CipherAlgorithm fromXmlId(String xmlId, int keySize) { for (CipherAlgorithm ca : CipherAlgorithm.values()) { if (!ca.xmlId.equals(xmlId)) continue; for (int ks : ca.allowedKeySize) { if (ks == keySize) return ca; } } throw new EncryptedDocumentException("cipher algorithm " + xmlId + "/" + keySize + " not found"); } }
public void init() throws GeneralSecurityException { if (isMSCapi(key)) { // see https://stackoverflow.com/questions/39196145 for problems with SunMSCAPI // and why we can't sign the calculated digest throw new EncryptedDocumentException( "Windows keystore entries can't be signed with the "+algo+" hash. Please "+ "use one digest algorithm of sha1 / sha256 / sha384 / sha512."); } md = CryptoFunctions.getMessageDigest(algo); }
@Override protected void setSalt(byte salt[]) { if (salt == null || salt.length != getCipherAlgorithm().blockSize) { throw new EncryptedDocumentException("invalid verifier salt"); } super.setSalt(salt); }
public void processPOIFSWriterEvent(POIFSWriterEvent event) { try { event.getStream().write(buf, 0, event.getLimit()); } catch (IOException e) { throw new EncryptedDocumentException(e); } } });