@Override public void confirmPassword(String password) { Random r = new SecureRandom(); byte salt[] = new byte[16]; byte verifier[] = new byte[16]; r.nextBytes(salt); r.nextBytes(verifier); confirmPassword(password, null, null, verifier, salt, null); }
@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); } }
/** * 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); }
/** * 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 CryptoAPIDocumentOutputStream(CryptoAPIEncryptor encryptor) throws GeneralSecurityException { this.encryptor = encryptor; cipher = encryptor.initCipherForBlock(null, 0); }
enc.setSummaryEntries(outFS.getRoot(), getEncryptedPropertyStreamName(), fs); } catch (GeneralSecurityException e) { throw new IOException(e);
/** * 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); } }
public void setBlock(int block) throws GeneralSecurityException { encryptor.initCipherForBlock(cipher, block); }
enc.setSummaryEntries(outFS.getRoot(), getEncryptedPropertyStreamName(), fs); } catch (GeneralSecurityException e) { throw new IOException(e);
@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); } }
@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); }
/** * 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 CryptoAPIDocumentOutputStream(CryptoAPIEncryptor encryptor) throws GeneralSecurityException { this.encryptor = encryptor; cipher = encryptor.initCipherForBlock(null, 0); }
@Override public void confirmPassword(String password) { Random r = new SecureRandom(); byte salt[] = new byte[16]; byte verifier[] = new byte[16]; r.nextBytes(salt); r.nextBytes(verifier); confirmPassword(password, null, null, verifier, salt, null); }
/** * 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); }
/** * 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); } }
public void setBlock(int block) throws GeneralSecurityException { encryptor.initCipherForBlock(cipher, block); }
@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); }