How to generate a unique hash code for string input in android…?

前端 未结 8 516
迷失自我
迷失自我 2020-12-13 03:41

I wanted to generate a unique hash code for a string in put in android. Is there any predefined library is there or we have to generate manually. Please any body if knows pl

8条回答
  •  隐瞒了意图╮
    2020-12-13 04:27

    I use this i tested it as key from my EhCacheManager Memory map ....

    Its cleaner i suppose

       /**
         * Return Hash256 of String value
         *
         * @param text
         * @return 
         */
        public static String getHash256(String text) {
            try {
                return org.apache.commons.codec.digest.DigestUtils.sha256Hex(text);
            } catch (Exception ex) {
                Logger.getLogger(HashUtil.class.getName()).log(Level.SEVERE, null, ex);
                return "";
            }
        }
    

    am using maven but this is the jar commons-codec-1.9.jar

提交回复
热议问题