001: /*
002: * $Id: AnyMD5.java,v 1.6 2002/09/16 08:05:02 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.core.crypto;
011:
012: import anvil.core.Any;
013: import anvil.core.AnyAbstractClass;
014: import anvil.core.io.AnyFile;
015: import anvil.core.net.AnyURL;
016: import anvil.script.Context;
017: import java.io.BufferedInputStream;
018: import java.io.File;
019: import java.io.FileInputStream;
020: import java.io.InputStream;
021: import java.io.IOException;
022: import java.net.URL;
023: import java.security.InvalidKeyException;
024: import java.security.MessageDigest;
025: import java.security.NoSuchAlgorithmException;
026: import javax.crypto.Mac;
027: import javax.crypto.SecretKey;
028: import javax.crypto.spec.SecretKeySpec;
029:
030: ///
031: /// @class MD5
032: /// This class is used for creating message hash codes:
033: /// <i>Message Digest</i> or <i>Message Authentication Code (MAC)</i>.
034: ///
035:
036: /**
037: * class MD5
038: *
039: * @author: Jaripekka Salminen
040: */
041: public class AnyMD5 extends AnyMessageHash {
042:
043: ///
044: /// @constructor MD5
045: /// @synopsis MD5 MD5() ; When the MD5 algorithm is used without
046: /// any key, it will return a MessageHash datatype, which will make
047: /// a <i>MD5 message digest</i> from the data given to it.
048: /// @synopsis MD5 MD5(object key) ; When the MD5 algorith is given
049: /// a key (string or binary), it will return a MessageHash datatype,
050: /// which will make a <i>HmacMD5 message authentication code</i>
051: /// from the data given to it.
052: ///
053: /// @param key string or binary key
054: /// @return message hash
055: ///
056: public static final Object[] newInstance = { null, "*key", null };
057:
058: public static final Any newInstance(Context context, Any key) {
059: CryptoModule.init();
060: try {
061: if (key == null) {
062: return new AnyMD5("MD5");
063: } else {
064: return new AnyMD5("HmacMD5", key);
065: }
066: } catch (Exception e) {
067: throw context.exception(e);
068: }
069: }
070:
071: public static final anvil.script.compiler.NativeClass __class__ = new anvil.script.compiler.NativeClass(
072: "MD5", AnyMD5.class,
073: AnyMessageHash.__class__,
074: //DOC{{
075: ""
076: + "\n"
077: + " @class MD5\n"
078: + " This class is used for creating message hash codes:\n"
079: + " <i>Message Digest</i> or <i>Message Authentication Code (MAC)</i>.\n"
080: + "\n"
081: + "\n"
082: + " @constructor MD5\n"
083: + " @synopsis MD5 MD5() ; When the MD5 algorithm is used without \n"
084: + " any key, it will return a MessageHash datatype, which will make \n"
085: + " a <i>MD5 message digest</i> from the data given to it.\n"
086: + " @synopsis MD5 MD5(object key) ; When the MD5 algorith is given\n"
087: + " a key (string or binary), it will return a MessageHash datatype, \n"
088: + " which will make a <i>HmacMD5 message authentication code</i>\n"
089: + " from the data given to it.\n" + " \n"
090: + " @param key string or binary key\n"
091: + " @return message hash\n" + "\n"
092: //}}DOC
093: );
094: static {
095: CryptoModule.class.getName();
096: }
097:
098: /*package*/AnyMD5(String algorithm)
099: throws NoSuchAlgorithmException {
100: super (algorithm);
101: }
102:
103: /*package*/AnyMD5(String algorithm, Any anyKey)
104: throws NoSuchAlgorithmException, InvalidKeyException {
105: super (algorithm, anyKey);
106: }
107:
108: public anvil.script.ClassType classOf() {
109: return __class__;
110: }
111:
112: }
|