问题描述
使用的算法如下,如何使生成的摘要长度为28,即rs.length()=28?importjava.security.MessageDigest;publicclassTestDigestextendsThread{publicstaticvoidmain(String[]args)throwsException{Stringtext="Testtesttestetsdata";bytedata[]=text.getBytes("GBK");MessageDigestm=MessageDigest.getInstance("SHA-1");m.update(data);byteresultData[]=m.digest();Stringrs=convertToHexString(resultData);System.out.println(rs+","+rs.length());}publicstaticStringconvertToHexString(bytedata[]){StringBufferstrBuffer=newStringBuffer();for(inti=0;i<data.length;i++){strBuffer.append(Integer.toHexString(0xff&data[i]));}returnstrBuffer.toString();}}
解决方案
时间: 2024-12-22 10:10:42