简体   繁体   English

在 Java 128 位 hash 中,32 位(13 位)将是纪元,其余位(86 位)一些 Z0800FC577294C34E0B28AD283943594

[英]In Java 128bit hash where 32bit (13 digits) would be epoch and remaining digit (86bit) some hash value

In Java 128bit hash where 32bit (13 digits) would be epoch and remaining digit (86 bit) some hash value在 Java 128 位 hash 中,32 位(13 位)将是纪元,其余位(86 位)一些 Z0800FC577294C34E0B28AD283943594

input -> string some random string of n size=
output-> 128bit or 38 digits number

39 digits(128 bits)=       epoch +some hashvalue
                    1475166540000+*************************

Could anyone suggest some hash function?谁能推荐一些 hash function?

The problem you're having is that 128 bits is not 39 digits, but only 4. If you're willing to change the length of the hash, you can do something like this (total 344 bits):您遇到的问题是 128 位不是 39 位,而是只有 4 位。如果您愿意更改 hash 的长度,您可以执行以下操作(总共 344 位):

String input = "abcdef";
String output = null;

try {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    byte[] hash = digest.digest(input.getBytes(StandardCharsets.UTF_8));

    output = System.currentTimeMillis() + new String(hash, StandardCharsets.UTF_8);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
}

System.out.println(output);  // Your new hash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM