What is the proper way to perform authenticated encryption in Java?

前端 未结 2 1010
一向
一向 2021-02-04 11:17

Authenticated encryption requires that we use some accepted standard for encrypting and authenticating a message. So we both encrypt the message and compute a MAC on the messag

相关标签:
2条回答
  • 2021-02-04 11:46

    When transferring files from one server to another through secure ftp, I use private/public key pairs with the private key residing on the "from" server and the public key residing on the "to" server.

    Using private/public key pairs is a secure standard when transferring files.

    I believe it would also be a secure means in the context of a Java application.

    Check out Generating and Verifying Signatures and Generate Public and Private Keys for more details on using a private/public key pair setup for digital signatures in Java.

    0 讨论(0)
  • 2021-02-04 12:00

    I would recommend using GCM mode encryption. It is included in the latest JDK (1.7) by default. It uses a counter mode encryption (a stream cipher, no padding required) and adds an authentication tag. One big advantage is that it requires only a single key, whereas HMAC adds another key to the mix. Bouncy Castle has an implementation as well, which is moslty compatible with one provided by Oracle.

    GCM mode encryption is also features in a TLS RFC, and in XML encrypt 1.1 (both not final). GCM mode provides all three security features: confidentiality, integrity and authenticity of the data send. The String would be "AES/GCM/NoPadding" instead of the CBC one you are now deploying. As said, make sure you have the latest JDK from Oracle, or have Bouncy Castle provider installed.

    Also check out my answer here, which is mostly about String encoding, but I've succesfully tried GCM mode too - see the comment.

    0 讨论(0)
提交回复
热议问题