비밀번호 암호화용 단방향이여서 복호화는 불가능 import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class SHA256 { public String encrypt(String text) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(text.getBytes()); return bytesToHex(md.digest()); } private String bytesToHex(byte[] bytes) { StringBuilder builder = new StringBui..
Hello !
try-with-resources는 try에 자원 객체를 전달하면, try 코드 블록이 끝나면 자동으로 자원을 종료해주는 기능이다. // 기존 코드 try{ Stream lineStream = Files.lines(Paths.get("file.txt"), StandardCharsets.UTF_8); System.out.println(Arrays.toString(lineStream.toArray())); }catch (IOException e){ e.printStackTrace(); } // try - with - resources try( Stream lineStream = Files.lines(Paths.get("file.txt"),StandardCharsets.UTF_8)) { System.out.p..
import java.util.Calendar; public class AgeTest { public static void main(String[] args) { System.out.println(getAge("220830") + "살"); } public static int getAge(String birth) { Calendar current = Calendar.getInstance(); int currentYear = current.get(Calendar.YEAR); int currentMonth = current.get(Calendar.MONTH) + 1; int currentDay = current.get(Calendar.DAY_OF_MONTH); int yearForCalculation = I..