• R/O
  • SSH
  • HTTPS

manjyudigest: Commit


Commit MetaInfo

Revision3 (tree)
Time2012-11-30 08:03:59
Authoriga

Log Message

New projejct.

Change Summary

Incremental Difference

--- manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestUtil.java (nonexistent)
+++ manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestUtil.java (revision 3)
@@ -0,0 +1,212 @@
1+/*******************************************************************************
2+ * ManjyuDigest
3+ * Copyright (C) 2012 Toshiki IGA
4+ *
5+ * This library is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Lesser General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Lesser General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Lesser General Public License
16+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
17+ *******************************************************************************/
18+/*******************************************************************************
19+ * Copyright (c) 2012 Toshiki IGA and others.
20+ * All rights reserved. This program and the accompanying materials
21+ * are made available under the terms of the Eclipse Public License v1.0
22+ * which accompanies this distribution, and is available at
23+ * http://www.eclipse.org/legal/epl-v10.html
24+ *
25+ * Contributors:
26+ * Toshiki IGA - initial API and implementation
27+ *******************************************************************************/
28+/*******************************************************************************
29+ * Copyright 2012 Toshiki IGA and others.
30+ *
31+ * Licensed under the Apache License, Version 2.0 (the "License");
32+ * you may not use this file except in compliance with the License.
33+ * You may obtain a copy of the License at
34+ *
35+ * http://www.apache.org/licenses/LICENSE-2.0
36+ *
37+ * Unless required by applicable law or agreed to in writing, software
38+ * distributed under the License is distributed on an "AS IS" BASIS,
39+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40+ * See the License for the specific language governing permissions and
41+ * limitations under the License.
42+ *******************************************************************************/
43+package org.manjyu.digest;
44+
45+import java.io.IOException;
46+import java.io.InputStream;
47+import java.io.UnsupportedEncodingException;
48+import java.security.MessageDigest;
49+import java.security.NoSuchAlgorithmException;
50+
51+/**
52+ * Message Digest Utility for Java.
53+ *
54+ * @author Toshiki Iga
55+ */
56+public class ManjyuDigestUtil {
57+ /**
58+ * Hide Constructor.
59+ */
60+ private ManjyuDigestUtil() {
61+ }
62+
63+ /**
64+ * Get message digest from given input stream.
65+ *
66+ * @param algorithm SHA1, SHA256, ...
67+ * @param inStream Input stream to message digest.
68+ * @return message digest.
69+ * @throws IOException
70+ */
71+ public static byte[] getDigestedMessage(final String algorithm, final InputStream inStream) throws IOException {
72+ try {
73+ final MessageDigest msgDigest = MessageDigest.getInstance(algorithm);
74+
75+ final byte[] buf = new byte[8192];
76+ for (;;) {
77+ final int length = inStream.read(buf, 0, buf.length);
78+ if (length < 0) {
79+ break;
80+ }
81+ msgDigest.update(buf, 0, length);
82+ }
83+
84+ return msgDigest.digest();
85+ } catch (NoSuchAlgorithmException ex) {
86+ throw new IllegalArgumentException("Specified algorithm [" + algorithm + "] not found.", ex);
87+ }
88+ }
89+
90+ /**
91+ * Get message digest from given value.
92+ *
93+ * @param algorithm SHA1, SHA256, ...
94+ * @param value1 value to message digest.
95+ * @return message digest.
96+ */
97+ public static byte[] getDigestedMessage(final String algorithm, final byte[] value1) {
98+ try {
99+ final MessageDigest msgDigest = MessageDigest.getInstance(algorithm);
100+ msgDigest.update(value1);
101+
102+ return msgDigest.digest();
103+ } catch (NoSuchAlgorithmException ex) {
104+ throw new IllegalArgumentException("Specified algorithm [" + algorithm + "] not found.", ex);
105+ }
106+ }
107+
108+ /**
109+ * Get message digest from given values.
110+ *
111+ * @param algorithm SHA1, SHA256, ...
112+ * @param value1 1st value to message digest.
113+ * @param value2 2nd value to message digest.
114+ * @return message digest.
115+ */
116+ public static byte[] getDigestedMessage(final String algorithm, final byte[] value1, final byte[] value2) {
117+ try {
118+ final MessageDigest msgDigest = MessageDigest.getInstance(algorithm);
119+ msgDigest.update(value1);
120+ msgDigest.update(value2);
121+
122+ return msgDigest.digest();
123+ } catch (NoSuchAlgorithmException ex) {
124+ throw new IllegalArgumentException("Specified algorithm [" + algorithm + "] not found.", ex);
125+ }
126+ }
127+
128+ /**
129+ * Get message digest from given values.
130+ *
131+ * @param algorithm SHA1, SHA256, ...
132+ * @param value1 1st value to message digest.
133+ * @param value2 2nd value to message digest.
134+ * @param value3 3rd value to message digest.
135+ * @return message digest.
136+ */
137+ public static byte[] getDigestedMessage(final String algorithm, final byte[] value1, final byte[] value2,
138+ final byte[] value3) {
139+ try {
140+ final MessageDigest msgDigest = MessageDigest.getInstance(algorithm);
141+ msgDigest.update(value1);
142+ msgDigest.update(value2);
143+ msgDigest.update(value3);
144+
145+ return msgDigest.digest();
146+ } catch (NoSuchAlgorithmException ex) {
147+ throw new IllegalArgumentException("Specified algorithm [" + algorithm + "] not found.", ex);
148+ }
149+ }
150+
151+ /**
152+ * Get message digest in hex string from given value.
153+ *
154+ * @param algorithm SHA1, SHA256, ...
155+ * @param value1 value to message digest.
156+ * @return message digest in hex string.
157+ */
158+ public static String getDigestedString(final String algorithm, final String value1) {
159+ try {
160+ final byte digestedValue[] = getDigestedMessage(algorithm, value1.getBytes("UTF-8"));
161+ return toHexString(digestedValue);
162+ } catch (UnsupportedEncodingException ex) {
163+ throw new IllegalArgumentException("Character encoding [UTF-8] not found.", ex);
164+ }
165+ }
166+
167+ /**
168+ * Get message digest in hex string from given values.
169+ *
170+ * @param algorithm SHA1, SHA256, ...
171+ * @param value1 1st value to message digest.
172+ * @param value2 2nd value to message digest.
173+ * @return message digest in hex string.
174+ */
175+ public static String getDigestedString(final String algorithm, final String value1, final String value2) {
176+ try {
177+ final byte digestedValue[] = getDigestedMessage(algorithm, value1.getBytes("UTF-8"),
178+ value2.getBytes("UTF-8"));
179+ return toHexString(digestedValue);
180+ } catch (UnsupportedEncodingException ex) {
181+ throw new IllegalArgumentException("Character encoding [UTF-8] not found.", ex);
182+ }
183+ }
184+
185+ /**
186+ * Get message digest in hex string from given values.
187+ *
188+ * @param algorithm SHA1, SHA256, ...
189+ * @param value1 1st value to message digest.
190+ * @param value2 2nd value to message digest.
191+ * @param value3 3rd value to message digest.
192+ * @return message digest in hex string.
193+ */
194+ public static String getDigestedString(final String algorithm, final String value1, final String value2,
195+ final String value3) {
196+ try {
197+ final byte digestedValue[] = getDigestedMessage(algorithm, value1.getBytes("UTF-8"),
198+ value2.getBytes("UTF-8"), value3.getBytes("UTF-8"));
199+ return toHexString(digestedValue);
200+ } catch (UnsupportedEncodingException ex) {
201+ throw new IllegalArgumentException("Character encoding [UTF-8] not found.", ex);
202+ }
203+ }
204+
205+ static String toHexString(byte[] argBytes) {
206+ final StringBuilder result = new StringBuilder();
207+ for (byte currentByte : argBytes) {
208+ result.append(String.format("%02x", currentByte));
209+ }
210+ return result.toString();
211+ }
212+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestMd5Util.java (nonexistent)
+++ manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestMd5Util.java (revision 3)
@@ -0,0 +1,120 @@
1+/*******************************************************************************
2+ * ManjyuDigest
3+ * Copyright (C) 2012 Toshiki IGA
4+ *
5+ * This library is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Lesser General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Lesser General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Lesser General Public License
16+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
17+ *******************************************************************************/
18+/*******************************************************************************
19+ * Copyright (c) 2012 Toshiki IGA and others.
20+ * All rights reserved. This program and the accompanying materials
21+ * are made available under the terms of the Eclipse Public License v1.0
22+ * which accompanies this distribution, and is available at
23+ * http://www.eclipse.org/legal/epl-v10.html
24+ *
25+ * Contributors:
26+ * Toshiki IGA - initial API and implementation
27+ *******************************************************************************/
28+/*******************************************************************************
29+ * Copyright 2012 Toshiki IGA and others.
30+ *
31+ * Licensed under the Apache License, Version 2.0 (the "License");
32+ * you may not use this file except in compliance with the License.
33+ * You may obtain a copy of the License at
34+ *
35+ * http://www.apache.org/licenses/LICENSE-2.0
36+ *
37+ * Unless required by applicable law or agreed to in writing, software
38+ * distributed under the License is distributed on an "AS IS" BASIS,
39+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40+ * See the License for the specific language governing permissions and
41+ * limitations under the License.
42+ *******************************************************************************/
43+package org.manjyu.digest;
44+
45+/**
46+ * MD5 Message Digest Utility for Java.
47+ *
48+ * RFC 1321
49+ *
50+ * @author Toshiki Iga
51+ */
52+public class ManjyuDigestMd5Util {
53+ public static final String ALGORITHM = "MD5";
54+
55+ /**
56+ * Get MD5 message digest from given value.
57+ *
58+ * @param value1 value to message digest.
59+ * @return message digest.
60+ */
61+ public static byte[] getDigestedMessage(final byte[] value1) {
62+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1);
63+ }
64+
65+ /**
66+ * Get MD5 message digest from given values.
67+ *
68+ * @param value1 1st value to message digest.
69+ * @param value2 2nd value to message digest.
70+ * @return message digest.
71+ */
72+ public static byte[] getDigestedMessage(final byte[] value1, final byte[] value2) {
73+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1, value2);
74+ }
75+
76+ /**
77+ * Get MD5 message digest from given values.
78+ *
79+ * @param value1 1st value to message digest.
80+ * @param value2 2nd value to message digest.
81+ * @param value3 3rd value to message digest.
82+ * @return message digest.
83+ */
84+ public static byte[] getDigestedMessage(final byte[] value1, final byte[] value2, final byte[] value3) {
85+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1, value2, value3);
86+ }
87+
88+ /**
89+ * Get MD5 message digest in hex string from given value.
90+ *
91+ * @param value1 value to message digest.
92+ * @return message digest in hex string.
93+ */
94+ public static String getDigestedString(final String value1) {
95+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1);
96+ }
97+
98+ /**
99+ * Get MD5 message digest in hex string from given values.
100+ *
101+ * @param value1 1st value to message digest.
102+ * @param value2 2nd value to message digest.
103+ * @return message digest in hex string.
104+ */
105+ public static String getDigestedString(final String value1, final String value2) {
106+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1, value2);
107+ }
108+
109+ /**
110+ * Get MD5 message digest in hex string from given values.
111+ *
112+ * @param value1 1st value to message digest.
113+ * @param value2 2nd value to message digest.
114+ * @param value3 3rd value to message digest.
115+ * @return message digest in hex string.
116+ */
117+ public static String getDigestedString(final String value1, final String value2, final String value3) {
118+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1, value2, value3);
119+ }
120+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestSha256Util.java (nonexistent)
+++ manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestSha256Util.java (revision 3)
@@ -0,0 +1,118 @@
1+/*******************************************************************************
2+ * ManjyuDigest
3+ * Copyright (C) 2012 Toshiki IGA
4+ *
5+ * This library is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Lesser General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Lesser General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Lesser General Public License
16+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
17+ *******************************************************************************/
18+/*******************************************************************************
19+ * Copyright (c) 2012 Toshiki IGA and others.
20+ * All rights reserved. This program and the accompanying materials
21+ * are made available under the terms of the Eclipse Public License v1.0
22+ * which accompanies this distribution, and is available at
23+ * http://www.eclipse.org/legal/epl-v10.html
24+ *
25+ * Contributors:
26+ * Toshiki IGA - initial API and implementation
27+ *******************************************************************************/
28+/*******************************************************************************
29+ * Copyright 2012 Toshiki IGA and others.
30+ *
31+ * Licensed under the Apache License, Version 2.0 (the "License");
32+ * you may not use this file except in compliance with the License.
33+ * You may obtain a copy of the License at
34+ *
35+ * http://www.apache.org/licenses/LICENSE-2.0
36+ *
37+ * Unless required by applicable law or agreed to in writing, software
38+ * distributed under the License is distributed on an "AS IS" BASIS,
39+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40+ * See the License for the specific language governing permissions and
41+ * limitations under the License.
42+ *******************************************************************************/
43+package org.manjyu.digest;
44+
45+/**
46+ * SHA-256 Message Digest Utility for Java.
47+ *
48+ * @author Toshiki Iga
49+ */
50+public class ManjyuDigestSha256Util {
51+ public static final String ALGORITHM = "SHA-256";
52+
53+ /**
54+ * Get SHA-256 message digest from given value.
55+ *
56+ * @param value1 value to message digest.
57+ * @return message digest.
58+ */
59+ public static byte[] getDigestedMessage(final byte[] value1) {
60+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1);
61+ }
62+
63+ /**
64+ * Get SHA-256 message digest from given values.
65+ *
66+ * @param value1 1st value to message digest.
67+ * @param value2 2nd value to message digest.
68+ * @return message digest.
69+ */
70+ public static byte[] getDigestedMessage(final byte[] value1, final byte[] value2) {
71+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1, value2);
72+ }
73+
74+ /**
75+ * Get SHA-256 message digest from given values.
76+ *
77+ * @param value1 1st value to message digest.
78+ * @param value2 2nd value to message digest.
79+ * @param value3 3rd value to message digest.
80+ * @return message digest.
81+ */
82+ public static byte[] getDigestedMessage(final byte[] value1, final byte[] value2, final byte[] value3) {
83+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1, value2, value3);
84+ }
85+
86+ /**
87+ * Get SHA-256 message digest in hex string from given value.
88+ *
89+ * @param value1 value to message digest.
90+ * @return message digest in hex string.
91+ */
92+ public static String getDigestedString(final String value1) {
93+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1);
94+ }
95+
96+ /**
97+ * Get SHA-256 message digest in hex string from given values.
98+ *
99+ * @param value1 1st value to message digest.
100+ * @param value2 2nd value to message digest.
101+ * @return message digest in hex string.
102+ */
103+ public static String getDigestedString(final String value1, final String value2) {
104+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1, value2);
105+ }
106+
107+ /**
108+ * Get SHA-256 message digest in hex string from given values.
109+ *
110+ * @param value1 1st value to message digest.
111+ * @param value2 2nd value to message digest.
112+ * @param value3 3rd value to message digest.
113+ * @return message digest in hex string.
114+ */
115+ public static String getDigestedString(final String value1, final String value2, final String value3) {
116+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1, value2, value3);
117+ }
118+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestSha1Util.java (nonexistent)
+++ manjyu-digest/trunk/src/org/manjyu/digest/ManjyuDigestSha1Util.java (revision 3)
@@ -0,0 +1,118 @@
1+/*******************************************************************************
2+ * ManjyuDigest
3+ * Copyright (C) 2012 Toshiki IGA
4+ *
5+ * This library is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Lesser General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Lesser General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Lesser General Public License
16+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
17+ *******************************************************************************/
18+/*******************************************************************************
19+ * Copyright (c) 2012 Toshiki IGA and others.
20+ * All rights reserved. This program and the accompanying materials
21+ * are made available under the terms of the Eclipse Public License v1.0
22+ * which accompanies this distribution, and is available at
23+ * http://www.eclipse.org/legal/epl-v10.html
24+ *
25+ * Contributors:
26+ * Toshiki IGA - initial API and implementation
27+ *******************************************************************************/
28+/*******************************************************************************
29+ * Copyright 2012 Toshiki IGA and others.
30+ *
31+ * Licensed under the Apache License, Version 2.0 (the "License");
32+ * you may not use this file except in compliance with the License.
33+ * You may obtain a copy of the License at
34+ *
35+ * http://www.apache.org/licenses/LICENSE-2.0
36+ *
37+ * Unless required by applicable law or agreed to in writing, software
38+ * distributed under the License is distributed on an "AS IS" BASIS,
39+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40+ * See the License for the specific language governing permissions and
41+ * limitations under the License.
42+ *******************************************************************************/
43+package org.manjyu.digest;
44+
45+/**
46+ * SHA-1 Message Digest Utility for Java.
47+ *
48+ * @author Toshiki Iga
49+ */
50+public class ManjyuDigestSha1Util {
51+ public static final String ALGORITHM = "SHA-1";
52+
53+ /**
54+ * Get SHA-1 message digest from given value.
55+ *
56+ * @param value1 value to message digest.
57+ * @return message digest.
58+ */
59+ public static byte[] getDigestedMessage(final byte[] value1) {
60+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1);
61+ }
62+
63+ /**
64+ * Get SHA-1 message digest from given values.
65+ *
66+ * @param value1 1st value to message digest.
67+ * @param value2 2nd value to message digest.
68+ * @return message digest.
69+ */
70+ public static byte[] getDigestedMessage(final byte[] value1, final byte[] value2) {
71+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1, value2);
72+ }
73+
74+ /**
75+ * Get SHA-1 message digest from given values.
76+ *
77+ * @param value1 1st value to message digest.
78+ * @param value2 2nd value to message digest.
79+ * @param value3 3rd value to message digest.
80+ * @return message digest.
81+ */
82+ public static byte[] getDigestedMessage(final byte[] value1, final byte[] value2, final byte[] value3) {
83+ return ManjyuDigestUtil.getDigestedMessage(ALGORITHM, value1, value2, value3);
84+ }
85+
86+ /**
87+ * Get SHA-1 message digest in hex string from given value.
88+ *
89+ * @param value1 value to message digest.
90+ * @return message digest in hex string.
91+ */
92+ public static String getDigestedString(final String value1) {
93+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1);
94+ }
95+
96+ /**
97+ * Get SHA-1 message digest in hex string from given values.
98+ *
99+ * @param value1 1st value to message digest.
100+ * @param value2 2nd value to message digest.
101+ * @return message digest in hex string.
102+ */
103+ public static String getDigestedString(final String value1, final String value2) {
104+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1, value2);
105+ }
106+
107+ /**
108+ * Get SHA-1 message digest in hex string from given values.
109+ *
110+ * @param value1 1st value to message digest.
111+ * @param value2 2nd value to message digest.
112+ * @param value3 3rd value to message digest.
113+ * @return message digest in hex string.
114+ */
115+ public static String getDigestedString(final String value1, final String value2, final String value3) {
116+ return ManjyuDigestUtil.getDigestedString(ALGORITHM, value1, value2, value3);
117+ }
118+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Show on old repository browser