HR자바 Java SHA-256

개요[ | ]

HR자바 Java SHA-256
해커랭크 Java
# 문제 비고
HR자바 Advanced e
53 HR자바 Java Varargs - Simple Addition
54 HR자바 Java Reflection - Attributes
55 HR자바 Can You Access?
56 HR자바 Prime Checker
57 HR자바 Java Factory Pattern
58 HR자바 Java Singleton Pattern
59 HR자바 Java Visitor Pattern
60 HR자바 Java Annotations
61 HR자바 Covariant Return Types
62 HR자바 Java Lambda Expressions
63 HR자바 Java MD5
64 HR자바 Java SHA-256

import java.io.*;
import java.util.*;

public class Solution {
    static String sha256(String s) {
        java.security.MessageDigest md;
        try { md = java.security.MessageDigest.getInstance("SHA-256"); }
        catch (Exception e) { return null; }
        md.update(s.getBytes());
        String result = (new java.math.BigInteger(1, md.digest())).toString(16);
        while(result.length()<64) { result = "0" + result; }
        return result;
    }
    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        System.out.println( sha256(str) );
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}