Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

java - Using BouncyCastle's ChaCha for file encryption

I'm hoping to encrypt a few files using ChaCha, so I wonder if it's appropriate to use Chacha20Poly1305. It seems that this class is designed for TLS, so does that mean it's not designed for file encryption? The methods inside, e.g., encodePlaintext() and decodeCiphertext() appear to work with text rather than binary files.

If that's the case, does anyone know how to work with BC's ChaCha implementation for file encryption?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...