@@ -39,7 +39,7 @@ public FileRecorder(String directory) throws IOException {
3939 */
4040 @ Override
4141 public void set (String key , byte [] data ) {
42- File f = new File (directory , sha256 (key ));
42+ File f = new File (directory , hash (key ));
4343 FileOutputStream fo = null ;
4444 try {
4545 fo = new FileOutputStream (f );
@@ -63,7 +63,7 @@ public void set(String key, byte[] data) {
6363 */
6464 @ Override
6565 public byte [] get (String key ) {
66- File f = new File (directory , sha256 (key ));
66+ File f = new File (directory , hash (key ));
6767 FileInputStream fi = null ;
6868 byte [] data = null ;
6969 int read = 0 ;
@@ -102,22 +102,19 @@ private boolean outOfDate(File f) {
102102 */
103103 @ Override
104104 public void del (String key ) {
105- File f = new File (directory , sha256 (key ));
105+ File f = new File (directory , hash (key ));
106106 f .delete ();
107107 }
108108
109- private static String sha256 (String base ) {
109+ private static String hash (String base ) {
110110 try {
111- MessageDigest digest = MessageDigest .getInstance ("SHA-256 " );
111+ MessageDigest digest = MessageDigest .getInstance ("SHA-1 " );
112112 byte [] hash = digest .digest (base .getBytes ());
113113 StringBuffer hexString = new StringBuffer ();
114114
115115 for (int i = 0 ; i < hash .length ; i ++) {
116- String hex = Integer .toHexString (0xff & hash [i ]);
117- if (hex .length () == 1 ) hexString .append ('0' );
118- hexString .append (hex );
116+ hexString .append (Integer .toString ((hash [i ] & 0xff ) + 0x100 , 16 ).substring (1 ));
119117 }
120-
121118 return hexString .toString ();
122119 } catch (Exception ex ) {
123120 ex .printStackTrace ();
0 commit comments