Java SHA-256

윤지현·2025년 3월 12일
0

HackerRank[Java]

목록 보기
14/57
  • 문제
  • 정답
import java.io.*;
import java.security.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-256");
            byte[] hashBytes = digest.digest(input.getBytes());
            
            StringBuilder hexString = new StringBuilder();
            for (byte b : hashBytes) {
                hexString.append(String.format("%02x", b));
            }
            
            System.out.println(hexString.toString());
        } catch(NoSuchAlgorithmException e) {
            System.out.println("Error: SHA-256 algorithm not found");
        }
    }
}
  • 결과
profile
첫 시작

0개의 댓글