@Override public boolean verifyPassword(String password) { EncryptionVerifier ver = getEncryptionInfo().getVerifier(); SecretKey skey = generateSecretKey(password, ver); try { Cipher cipher = initCipherForBlock(null, 0, getEncryptionInfo(), skey, Cipher.DECRYPT_MODE); byte encryptedVerifier[] = ver.getEncryptedVerifier(); byte verifier[] = new byte[encryptedVerifier.length]; cipher.update(encryptedVerifier, 0, encryptedVerifier.length, verifier); setVerifier(verifier); byte encryptedVerifierHash[] = ver.getEncryptedVerifierHash(); byte verifierHash[] = cipher.doFinal(encryptedVerifierHash); HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); byte calcVerifierHash[] = hashAlg.digest(verifier); if (Arrays.equals(calcVerifierHash, verifierHash)) { setSecretKey(skey); return true; } } catch (GeneralSecurityException e) { throw new EncryptedDocumentException(e); } return false; }
@Override public Cipher initCipherForBlock(Cipher cipher, int block) throws GeneralSecurityException { EncryptionInfo ei = getEncryptionInfo(); SecretKey sk = getSecretKey(); return initCipherForBlock(cipher, block, ei, sk, Cipher.DECRYPT_MODE); }
/** * initialize the builder from a stream */ @Override public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { /* int hSize = */ dis.readInt(); CryptoAPIEncryptionHeader header = new CryptoAPIEncryptionHeader(dis); info.setHeader(header); info.setVerifier(new CryptoAPIEncryptionVerifier(dis, header)); CryptoAPIDecryptor dec = new CryptoAPIDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); CryptoAPIEncryptor enc = new CryptoAPIEncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); }
public CryptoAPIDocumentInputStream(CryptoAPIDecryptor decryptor, byte buf[]) throws GeneralSecurityException { super(buf); this.decryptor = decryptor; cipher = decryptor.initCipherForBlock(null, 0); } }
@Override public void confirmPassword(String password, byte keySpec[], byte keySalt[], byte verifier[], byte verifierSalt[], byte integritySalt[]) { assert(verifier != null && verifierSalt != null); CryptoAPIEncryptionVerifier ver = (CryptoAPIEncryptionVerifier)getEncryptionInfo().getVerifier(); ver.setSalt(verifierSalt); SecretKey skey = CryptoAPIDecryptor.generateSecretKey(password, ver); setSecretKey(skey); try { Cipher cipher = initCipherForBlock(null, 0); byte encryptedVerifier[] = new byte[verifier.length]; cipher.update(verifier, 0, verifier.length, encryptedVerifier); ver.setEncryptedVerifier(encryptedVerifier); HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); byte calcVerifierHash[] = hashAlg.digest(verifier); byte encryptedVerifierHash[] = cipher.doFinal(calcVerifierHash); ver.setEncryptedVerifierHash(encryptedVerifierHash); } catch (GeneralSecurityException e) { throw new EncryptedDocumentException("Password confirmation failed", e); } }
encPoifs = dec.getSummaryEntries(dirNode, encryptedStream); dirNode = encPoifs.getRoot();
/** * initialize the builder from scratch */ @Override public void initialize(EncryptionInfo info, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) { if (cipherAlgorithm == null) { cipherAlgorithm = CipherAlgorithm.rc4; } if (hashAlgorithm == null) { hashAlgorithm = HashAlgorithm.sha1; } if (keyBits == -1) { keyBits = 0x28; } assert(cipherAlgorithm == CipherAlgorithm.rc4 && hashAlgorithm == HashAlgorithm.sha1); info.setHeader(new CryptoAPIEncryptionHeader(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode)); info.setVerifier(new CryptoAPIEncryptionVerifier(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode)); CryptoAPIDecryptor dec = new CryptoAPIDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); CryptoAPIEncryptor enc = new CryptoAPIEncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); } }
@Override protected Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException { return CryptoAPIDecryptor.this.initCipherForBlock(existing, block); }
@Override public void confirmPassword(String password, byte keySpec[], byte keySalt[], byte verifier[], byte verifierSalt[], byte integritySalt[]) { assert(verifier != null && verifierSalt != null); CryptoAPIEncryptionVerifier ver = (CryptoAPIEncryptionVerifier)getEncryptionInfo().getVerifier(); ver.setSalt(verifierSalt); SecretKey skey = CryptoAPIDecryptor.generateSecretKey(password, ver); setSecretKey(skey); try { Cipher cipher = initCipherForBlock(null, 0); byte encryptedVerifier[] = new byte[verifier.length]; cipher.update(verifier, 0, verifier.length, encryptedVerifier); ver.setEncryptedVerifier(encryptedVerifier); HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); byte calcVerifierHash[] = hashAlg.digest(verifier); byte encryptedVerifierHash[] = cipher.doFinal(calcVerifierHash); ver.setEncryptedVerifierHash(encryptedVerifierHash); } catch (GeneralSecurityException e) { throw new EncryptedDocumentException("Password confirmation failed", e); } }
encPoifs = dec.getSummaryEntries(dirNode, encryptedStream); dirNode = encPoifs.getRoot();
@Override public boolean verifyPassword(String password) { EncryptionVerifier ver = getEncryptionInfo().getVerifier(); SecretKey skey = generateSecretKey(password, ver); try { Cipher cipher = initCipherForBlock(null, 0, getEncryptionInfo(), skey, Cipher.DECRYPT_MODE); byte encryptedVerifier[] = ver.getEncryptedVerifier(); byte verifier[] = new byte[encryptedVerifier.length]; cipher.update(encryptedVerifier, 0, encryptedVerifier.length, verifier); setVerifier(verifier); byte encryptedVerifierHash[] = ver.getEncryptedVerifierHash(); byte verifierHash[] = cipher.doFinal(encryptedVerifierHash); HashAlgorithm hashAlgo = ver.getHashAlgorithm(); MessageDigest hashAlg = CryptoFunctions.getMessageDigest(hashAlgo); byte calcVerifierHash[] = hashAlg.digest(verifier); if (Arrays.equals(calcVerifierHash, verifierHash)) { setSecretKey(skey); return true; } } catch (GeneralSecurityException e) { throw new EncryptedDocumentException(e); } return false; }
@Override public Cipher initCipherForBlock(Cipher cipher, int block) throws GeneralSecurityException { EncryptionInfo ei = getEncryptionInfo(); SecretKey sk = getSecretKey(); return initCipherForBlock(cipher, block, ei, sk, Cipher.DECRYPT_MODE); }
/** * initialize the builder from a stream */ @Override public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { /* int hSize = */ dis.readInt(); CryptoAPIEncryptionHeader header = new CryptoAPIEncryptionHeader(dis); info.setHeader(header); info.setVerifier(new CryptoAPIEncryptionVerifier(dis, header)); CryptoAPIDecryptor dec = new CryptoAPIDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); CryptoAPIEncryptor enc = new CryptoAPIEncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); }
public void setBlock(int block) throws GeneralSecurityException { cipher = decryptor.initCipherForBlock(cipher, block); }
/** * initialize the builder from scratch */ @Override public void initialize(EncryptionInfo info, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) { if (cipherAlgorithm == null) { cipherAlgorithm = CipherAlgorithm.rc4; } if (hashAlgorithm == null) { hashAlgorithm = HashAlgorithm.sha1; } if (keyBits == -1) { keyBits = 0x28; } assert(cipherAlgorithm == CipherAlgorithm.rc4 && hashAlgorithm == HashAlgorithm.sha1); info.setHeader(new CryptoAPIEncryptionHeader(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode)); info.setVerifier(new CryptoAPIEncryptionVerifier(cipherAlgorithm, hashAlgorithm, keyBits, blockSize, chainingMode)); CryptoAPIDecryptor dec = new CryptoAPIDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); CryptoAPIEncryptor enc = new CryptoAPIEncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); } }
/** * 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 when the cipher can't be initialized */ public Cipher initCipherForBlock(Cipher cipher, int block) throws GeneralSecurityException { return CryptoAPIDecryptor.initCipherForBlock(cipher, block, getEncryptionInfo(), getSecretKey(), Cipher.ENCRYPT_MODE); }
@Override protected Cipher initCipherForBlock(Cipher cipher, int block, boolean lastChunk) throws IOException, GeneralSecurityException { flush(); EncryptionInfo ei = getEncryptionInfo(); SecretKey sk = getSecretKey(); return CryptoAPIDecryptor.initCipherForBlock(cipher, block, ei, sk, Cipher.ENCRYPT_MODE); }
public CryptoAPIDocumentInputStream(CryptoAPIDecryptor decryptor, byte buf[]) throws GeneralSecurityException { super(buf); this.decryptor = decryptor; cipher = decryptor.initCipherForBlock(null, 0); } }
@Override protected Cipher initCipherForBlock(Cipher existing, int block) throws GeneralSecurityException { return CryptoAPIDecryptor.this.initCipherForBlock(existing, block); }
public void setBlock(int block) throws GeneralSecurityException { cipher = decryptor.initCipherForBlock(cipher, block); }