Lav*_*wal 2 javascript java hash android sha512
下面的函数用于JavaScript(forms.js include)用于散列密码.什么是JAVA中的等价物,
function formhash(form, password) {
console.log("Hashing form");
// Create a new element input, this will be our hashed password field.
var p = document.createElement("input");
// Add the new element to our form.
form.appendChild(p);
p.name = "p";
p.type = "hidden"
p.value = hex_sha512(password.value);
// Make sure the plaintext password doesn't get sent.
password.value = "";
// Finally submit the form.
form.submit();
}
Run Code Online (Sandbox Code Playgroud)
这是执行它的代码.复制自http://runnable.com/U8lo-rXJWGlhL-OG/sha512-for-java
import java.security.MessageDigest;
public class SHA512 {
public static void main(String args[]) throws Exception {
String password = "pass@word1";
if ((args.length == 1) && (args[0].length() > 0))
{
password = args[0];
}
System.out.println("Password: " + password + " in SHA512 is:");
System.out.println(hashText(password));
}
public static String convertByteToHex(byte data[])
{
StringBuffer hexData = new StringBuffer();
for (int byteIndex = 0; byteIndex < data.length; byteIndex++)
hexData.append(Integer.toString((data[byteIndex] & 0xff) + 0x100, 16).substring(1));
return hexData.toString();
}
public static String hashText(String textToHash) throws Exception
{
final MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
sha512.update(textToHash.getBytes());
return convertByteToHex(sha512.digest());
}
}
Run Code Online (Sandbox Code Playgroud)
[编辑]
如果使用不同的字符集,请将其传递给getBytes.例textToHash.getBytes("UTF-8")
| 归档时间: |
|
| 查看次数: |
532 次 |
| 最近记录: |