Module org.cryptomator.cryptolib
Package org.cryptomator.cryptolib.api
High-level encryption library used in Cryptomator.
Example Usage:
// Define a pepper used during JSON serialization: MasterkeyFileAccess masterkeyFileAccess = new MasterkeyFileAccess(pepper, csprng); // Create new masterkey and safe it to a file: SecureRandom csprng = SecureRandom.getInstanceStrong(); Masterkey masterkey =Masterkey.generate(csprng);masterkeyFileAccess.persist(masterkey, path, passphrase); // Load a masterkey from a file: Masterkey masterkey =masterkeyFileAccess.load(path, passphrase); // Create new cryptor:Cryptorcryptor =CryptorProvider.forScheme(SIV_GCM).provide(masterkey, csprng); // Each directory needs a (relatively) unique ID, which affects the encryption/decryption of child names: String uniqueIdOfDirectory = UUID.randomUUID().toString(); // Encrypt and decrypt file name: String cleartextFileName = "foo.txt"; String encryptedName = cryptor.fileNameCryptor().encryptFilename(base32, cleartextFileName, uniqueIdOfDirectory.getBytes()); String decryptedName = cryptor.fileNameCryptor().decryptFilename(base32, encryptedName, uniqueIdOfDirectory.getBytes()); // Encrypt file contents: ByteBuffer plaintext = ...; SeekableByteChannel ciphertextOut = ...; try (WritableByteChannel ch = newEncryptingWritableByteChannel(ciphertextOut, cryptor)) { ch.write(plaintext); } // Decrypt file contents: ReadableByteChannel ciphertextIn = ...; try (ReadableByteChannel ch = newDecryptingReadableByteChannel(ciphertextOut, cryptor, true)) { ch.read(plaintext); }
-
Interface Summary Interface Description Cryptor CryptorProvider FileContentCryptor FileHeader FileHeaderCryptor FileNameCryptor Provides deterministic encryption capabilities as filenames must not change on subsequent encryption attempts, otherwise each change results in major directory structure changes which would be a terrible idea for cloud storage encryption.MasterkeyLoader Masterkey loaders load keys to unlock Cryptomator vaults. -
Class Summary Class Description Masterkey -
Enum Summary Enum Description CryptorProvider.Scheme A combination of ciphers to use for filename and file content encryption -
Exception Summary Exception Description AuthenticationFailedException CryptoException InvalidPassphraseException MasterkeyLoadingFailedException UnsupportedVaultFormatException