@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 protected void createEncryptionInfoEntry(DirectoryNode dir, File tmpFile) throws IOException, GeneralSecurityException { BinaryRC4Encryptor.this.createEncryptionInfoEntry(dir); }
@Override protected Cipher initCipherForBlock(Cipher cipher, int block, boolean lastChunk) throws GeneralSecurityException { return BinaryRC4Decryptor.initCipherForBlock(cipher, block, getEncryptionInfo(), getSecretKey(), Cipher.ENCRYPT_MODE); }
@Override public void confirmPassword(String password, byte keySpec[], byte keySalt[], byte verifier[], byte verifierSalt[], byte integritySalt[]) { BinaryRC4EncryptionVerifier ver = (BinaryRC4EncryptionVerifier)getEncryptionInfo().getVerifier(); ver.setSalt(verifierSalt); SecretKey skey = BinaryRC4Decryptor.generateSecretKey(password, ver); setSecretKey(skey); try { Cipher cipher = BinaryRC4Decryptor.initCipherForBlock(null, 0, getEncryptionInfo(), skey, Cipher.ENCRYPT_MODE); byte encryptedVerifier[] = new byte[16]; cipher.update(verifier, 0, 16, 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 public void initialize(EncryptionInfo info, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) { info.setHeader(new BinaryRC4EncryptionHeader()); info.setVerifier(new BinaryRC4EncryptionVerifier()); Decryptor dec = new BinaryRC4Decryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new BinaryRC4Encryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); } }
protected int getKeySizeInBytes() { return getEncryptionInfo().getHeader().getKeySize() / 8; }
@Override public void confirmPassword(String password, byte keySpec[], byte keySalt[], byte verifier[], byte verifierSalt[], byte integritySalt[]) { BinaryRC4EncryptionVerifier ver = (BinaryRC4EncryptionVerifier)getEncryptionInfo().getVerifier(); ver.setSalt(verifierSalt); SecretKey skey = BinaryRC4Decryptor.generateSecretKey(password, ver); setSecretKey(skey); try { Cipher cipher = BinaryRC4Decryptor.initCipherForBlock(null, 0, getEncryptionInfo(), skey, Cipher.ENCRYPT_MODE); byte encryptedVerifier[] = new byte[16]; cipher.update(verifier, 0, 16, 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 public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { int vMajor = info.getVersionMajor(); int vMinor = info.getVersionMinor(); assert (vMajor == 1 && vMinor == 1); info.setHeader(new BinaryRC4EncryptionHeader()); info.setVerifier(new BinaryRC4EncryptionVerifier(dis)); Decryptor dec = new BinaryRC4Decryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new BinaryRC4Encryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); }
protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException { DataSpaceMapUtils.addDefaultDataSpace(dir); final EncryptionInfo info = getEncryptionInfo(); final BinaryRC4EncryptionHeader header = (BinaryRC4EncryptionHeader)info.getHeader(); final BinaryRC4EncryptionVerifier verifier = (BinaryRC4EncryptionVerifier)info.getVerifier(); EncryptionRecord er = new EncryptionRecord() { @Override public void write(LittleEndianByteArrayOutputStream bos) { bos.writeShort(info.getVersionMajor()); bos.writeShort(info.getVersionMinor()); header.write(bos); verifier.write(bos); } }; DataSpaceMapUtils.createEncryptionEntry(dir, "EncryptionInfo", er); }
@Override protected Cipher initCipherForBlock(Cipher cipher, int block, boolean lastChunk) throws GeneralSecurityException { return BinaryRC4Decryptor.initCipherForBlock(cipher, block, getEncryptionInfo(), getSecretKey(), Cipher.ENCRYPT_MODE); }
@Override public void initialize(EncryptionInfo info, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) { info.setHeader(new BinaryRC4EncryptionHeader()); info.setVerifier(new BinaryRC4EncryptionVerifier()); Decryptor dec = new BinaryRC4Decryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new BinaryRC4Encryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); } }
protected int getKeySizeInBytes() { return getEncryptionInfo().getHeader().getKeySize() / 8; }
@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 protected void createEncryptionInfoEntry(DirectoryNode dir, File tmpFile) throws IOException, GeneralSecurityException { BinaryRC4Encryptor.this.createEncryptionInfoEntry(dir); }
@Override public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { int vMajor = info.getVersionMajor(); int vMinor = info.getVersionMinor(); assert (vMajor == 1 && vMinor == 1); info.setHeader(new BinaryRC4EncryptionHeader()); info.setVerifier(new BinaryRC4EncryptionVerifier(dis)); Decryptor dec = new BinaryRC4Decryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new BinaryRC4Encryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); }
protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException { DataSpaceMapUtils.addDefaultDataSpace(dir); final EncryptionInfo info = getEncryptionInfo(); final BinaryRC4EncryptionHeader header = (BinaryRC4EncryptionHeader)info.getHeader(); final BinaryRC4EncryptionVerifier verifier = (BinaryRC4EncryptionVerifier)info.getVerifier(); EncryptionRecord er = new EncryptionRecord() { @Override public void write(LittleEndianByteArrayOutputStream bos) { bos.writeShort(info.getVersionMajor()); bos.writeShort(info.getVersionMinor()); header.write(bos); verifier.write(bos); } }; DataSpaceMapUtils.createEncryptionEntry(dir, "EncryptionInfo", er); }