What does update method of MessageDigest do and what is BASE64Encoder meant for?

前端 未结 5 1231
不知归路
不知归路 2021-02-06 06:25

Following is a code that will encrypts the user String :

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.No         


        
5条回答
  •  半阙折子戏
    2021-02-06 07:02

    For Base64 encryption and decryption this warning clearly says that it does not encourage the use of Sun implementation of Base64Encoder and gives a warning that the implementation may be removed in future releases, what we can do is to switch to other implementation of Base64 encoder. We can use Commons Codec library for Base64 Encoder. Following is an example:

    1. Add Commons Codec library in classpath of your project
    2. Add import statement for Base64 Class.
    
    import org.apache.commons.codec.binary.Base64;
    
    3. Encrypt your data
    
    String testString = "Hello World";
    byte[] encodedBytes = Base64.encodeBase64(testString.getBytes());
    // Get encoded string
    String encodedString = new String(encodedBytes);
    // Get decoded string back
    String decodedString = new String(Base64.decodeBase64(encodedBytes));
    

    After using Commons codec library, you should not see above warning again.

提交回复
热议问题