You can simply use the ChaChaEngine
class that is referenced by the Chacha20Poly1305
class. The Engine
classes contain implementations of the various cipher classes.
Besides that, the JCA provides a higher level API to work with the various ciphers. So you can also use:
Security.addProvider(new BouncyCastleProvider());
Cipher c = Cipher.getInstance("ChaCha");
After which the normal Java CipherInputStream
and CipherOutputStream
will become available.
Note that using Poly1305 does provide additional authentication. This is often not a requirement for file encryption, but it does provide an additional layer of security. If you want to have authenticated encryption and you cannot work out how, then please ask a separate question.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…