• R/O
  • SSH
  • HTTPS

webserver: Commit


Commit MetaInfo

Revision59 (tree)
Time2010-10-25 00:52:37
Authorhoritaku

Log Message

edit

Change Summary

Incremental Difference

--- branch/Basic 0.2x/import_lib/lib/crypt/CodeMD5.java (revision 0)
+++ branch/Basic 0.2x/import_lib/lib/crypt/CodeMD5.java (revision 59)
@@ -0,0 +1,73 @@
1+package lib.crypt;
2+
3+import java.io.IOException;
4+import java.io.InputStream;
5+import java.security.MessageDigest;
6+import java.security.NoSuchAlgorithmException;
7+
8+public class CodeMD5 {
9+
10+ public static String crypt(String str) throws NoSuchAlgorithmException {
11+ if (str == null || str.length() == 0) {
12+ throw new IllegalArgumentException("String to encript cannot be null or zero length");
13+ }
14+
15+ MessageDigest md = MessageDigest.getInstance("MD5");
16+ md.update(str.getBytes());
17+ byte[] hash = md.digest();
18+
19+ return hashByte2MD5(hash);
20+ }
21+
22+ public static String crypt(byte [] bytes) throws NoSuchAlgorithmException {
23+ if (bytes == null || bytes.length == 0) {
24+ throw new IllegalArgumentException("bytes to encript cannot be null or zero length");
25+ }
26+ MessageDigest digest = MessageDigest.getInstance("MD5");
27+ byte[] hash = digest.digest(bytes);
28+
29+ return hashByte2MD5(hash);
30+ }
31+
32+ public static String crypt(InputStream in) throws NoSuchAlgorithmException, IOException {
33+ if (in == null || in.available() == 0) {
34+ throw new IllegalArgumentException("InputStream can't be null or zero length.");
35+ }
36+
37+ MessageDigest digest = MessageDigest.getInstance("MD5");
38+ try {
39+ byte[] buff = new byte[4096];
40+ int len = 0;
41+ while ((len = in.read(buff, 0, buff.length)) >= 0) {
42+ digest.update(buff, 0, len);
43+ }
44+ } catch (IOException e) {
45+ throw e;
46+ } finally {
47+ if (in != null) {
48+ try {
49+ in.close();
50+ } catch (IOException e) {
51+ e.printStackTrace();
52+ }
53+ }
54+ }
55+ byte[] hash = digest.digest();
56+
57+ return hashByte2MD5(hash);
58+ }
59+
60+ //MD5 ハッシュ関数
61+ private static String hashByte2MD5(byte []hash) {
62+ StringBuffer hexString = new StringBuffer();
63+ for (int i = 0; i < hash.length; i++) {
64+ if ((0xff & hash[i]) < 0x10) {
65+ hexString.append("0" + Integer.toHexString((0xFF & hash[i])));
66+ } else {
67+ hexString.append(Integer.toHexString(0xFF & hash[i]));
68+ }
69+ }
70+
71+ return hexString.toString();
72+ }
73+}
--- branch/Basic 0.2x/config/user_pass.ini (revision 0)
+++ branch/Basic 0.2x/config/user_pass.ini (revision 59)
@@ -0,0 +1 @@
1+tak=6380c8c28e1cddb21a42ac0c32472cf1
\ No newline at end of file
Show on old repository browser