0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

java。base64エンコード。標準ライブラリ。spring frameworkのライブラリの例

Posted at

標準ライブラリでのBase64エンコード

import java.util.Base64;

public class Base64Example {
    public static void main(String[] args) {
        String originalInput = "Hello, World!";
        
        // Base64エンコード
        String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes());
        System.out.println("Encoded String: " + encodedString);
        
        // Base64デコード
        byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
        String decodedString = new String(decodedBytes);
        System.out.println("Decoded String: " + decodedString);
    }
}

Spring FrameworkでのBase64エンコード

import org.springframework.util.Base64Utils;

public class SpringBase64Example {
    public static void main(String[] args) {
        String originalInput = "Hello, World!";
        
        // Base64エンコード
        String encodedString = Base64Utils.encodeToString(originalInput.getBytes());
        System.out.println("Encoded String: " + encodedString);
        
        // Base64デコード
        byte[] decodedBytes = Base64Utils.decodeFromString(encodedString);
        String decodedString = new String(decodedBytes);
        System.out.println("Decoded String: " + decodedString);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?