Created
August 17, 2016 06:51
-
-
Save jb7959/d4528d64ca17428401f1f28a0e6144a0 to your computer and use it in GitHub Desktop.
SHA-512 Encryption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Encryption { | |
private String userPassword; | |
/** | |
* 패스워드 암호화 | |
* @param userPassword | |
* 사용자 패스워드 | |
* @return 암호화 된 사용자 패스워드 | |
* 암호화 방식 : SHA-512 | |
*/ | |
public boolean encryption(String userPassword) { | |
MessageDigest md; | |
boolean isSuccess; | |
String tempPassword = ""; | |
try { | |
md = MessageDigest.getInstance("SHA-512"); | |
md.update(userPassword.getBytes()); | |
byte[] mb = md.digest(); | |
for (int i = 0; i < mb.length; i++) { | |
byte temp = mb[i]; | |
String s = Integer.toHexString(new Byte(temp)); | |
while (s.length() < 2) { | |
s = "0" + s; | |
} | |
s = s.substring(s.length() - 2); | |
tempPassword += s; | |
} | |
setPassword(tempPassword); | |
isSuccess = true; | |
} catch (NoSuchAlgorithmException e) { | |
isSuccess = false; | |
return isSuccess; | |
} | |
return isSuccess; | |
} | |
private void setPassword(String temppassword) { | |
this.userPassword = temppassword; | |
} | |
public String getPassword() { | |
return userPassword; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment