Using BouncyCastle's ChaCha for file encryption

前端 未结 3 557
自闭症患者
自闭症患者 2020-12-17 05:43

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

3条回答
  •  借酒劲吻你
    2020-12-17 06:31

    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.

提交回复
热议问题