【问题标题】:In Java 128bit hash where 32bit (13 digits) would be epoch and remaining digit (86bit) some hash value在 Java 128 位散列中,其中 32 位(13 位)将是纪元,其余位(86 位)是一些散列值
【发布时间】:2021-06-03 07:22:11
【问题描述】:

在 Java 128 位散列中,其中 32 位(13 位)将是纪元,其余位(86 位)是一些散列值

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

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

谁能推荐一些哈希函数?

【问题讨论】:

    标签: java oracle hashcode hash-function


    【解决方案1】:

    您遇到的问题是 128 位不是 39 位,而是只有 4 位。如果您愿意更改哈希的长度,可以执行以下操作(总共 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
    

    【讨论】:

    • 我想创建一个 38 位数字(128 位),它将存储在 Oracle Number 数据类型中,并且纪元编号组件将充当尾随数字,我想在其中使用纪元进行查询。即在两个纪元之间。
    猜你喜欢
    • 2012-07-13
    • 2010-10-29
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2011-07-30
    • 2021-12-11
    • 1970-01-01
    • 2013-12-12
    相关资源
    最近更新 更多