//============================================================================== // MyProvider.java //============================================================================== package tribble.crypto; // System imports import java.lang.Exception; import java.lang.String; import java.lang.System; import java.security.NoSuchAlgorithmException; import java.security.Provider; import java.security.ProviderException; import javax.crypto.NoSuchPaddingException; /******************************************************************************* * Cryptographic implementation provider for this package. * *

* References *

* java.sun.com/docs/1.4.0/guide/security/jce/HowToImplAJCEProvider.html. * * * @version API 2, $Revision: 1.3 $ $Date: 2005/09/11 03:20:07 $ * @since JCE 1.2 / JRE 1.4, 2005-04-01 * @author * David R. Tribble * (david@tribble.com). * *

* Copyright ©2005 by David R. Tribble, all rights reserved. *
* Permission is granted to freely use and distribute this source code * provided that the original copyright and authorship notices remain * intact. * * @see Cipher */ public class MyProvider extends java.security.Provider { // Identification /** Revision information. */ static final String REV = "@(#)tribble/crypto/MyProvider.java $Revision: 1.3 $ $Date: 2005/09/11 03:20:07 $\n"; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Constants /** Provider name for this package. */ static final String NAME = "david.tribble.com"; /** Provider version number (1.0). */ static final double VERSION = 1.0; /** Provider description. */ static final String DESCRIPTION = "Cryptographic algorithms, by David R Tribble, 2005."; /** List of encryption (cipher) algorithms provided in this package. * *

* Contains a list of provider names and their implementation classes, * in the form of: *

    *    { "Cipher.alg", "pkg.class" } 
* where alg specifies the "standard" name of the encryption * algorithm, and pkg.class is the actual implementation package and * class name. * *

* The alg name can be a single algorithm name (e.g., "DES"); * or it can be composed of two parts "alg/mode", * specifying an algorithm and a block mode (e.g., "DES/CBC"); * or it can be composed of three parts * "alg/mode/pad", specifying an additional * padding type (e.g., "DES/CBC/PKCS5Padding"), and the mode * part can be left unspecified (e.g., "DES//PKCS5Padding"). * *

* Valid mode settings are: *

    *    ECB, CBC, CFB, OFB, PCBC 
* *

* Valid pad settings are: *

    *    PKCS5Padding 
* * @since 1.1, 2005-04-01 */ private static final String[][] ALGORITHMS = { { "Cipher.Null", "tribble.crypto.NullCipher" }, { "Cipher.AES", "tribble.crypto.AESCipher" }, { "Cipher.AES128", "tribble.crypto.AESCipher" }, { "Cipher.AES192", "tribble.crypto.AESCipher" }, { "Cipher.AES256", "tribble.crypto.AESCipher" }, { "Cipher.IDEA", "tribble.crypto.IDEACipher" }, { "Cipher.TEA", "tribble.crypto.TEACipher" }, { "Cipher.RSA", "tribble.crypto.RSACipher" }, { "Cipher.Zoidfarb", "tribble.crypto.ZoidfarbCipher" }, { "Cipher.ZoidfarbC", "tribble.crypto.ZoidfarbCipher" }, // etc. }; /** Cryptographic cipher classes. * +INCOMPLETE * * @since 1.3, 2005-09-10 */ private static final String[][] ALGORITHMS2 = { { "AES/NoPadding/ECB", "AESCipher", "SymmetricCipherSpi" }, { "AES/NoPadding/ECB", "AESCipher", "SymmetricCipherSpi" }, { "AES/NoPadding/CBC", "AESCipher", "SymmetricCipherSpi" }, { "AES/NoPadding/PBC", "AESCipher", "SymmetricCipherSpi" }, { "AES/NoPadding/CFB", "AESCipher", "StreamCipherSpi" }, { "AES/NoPadding/CFB8", "AESCipher", "StreamCipherSpi" }, { "AES/NoPadding/OFB", "AESCipher", "StreamCipherSpi" }, { "AES/NoPadding/OFB8", "AESCipher", "StreamCipherSpi" }, { "AES/NoPadding/PFB", "AESCipher", "StreamCipherSpi" }, { "AES/NoPadding/PFB8", "AESCipher", "StreamCipherSpi" }, { "AES/PKCS5Padding/ECB", "AESCipher", "SymmetricCipherSpi" }, { "AES/PKCS5Padding/CBC", "AESCipher", "SymmetricCipherSpi" }, { "AES/PKCS5Padding/PBC", "AESCipher", "SymmetricCipherSpi" }, // etc. }; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Static variables /** Cryptographic provider embodied by this package. */ public static final MyProvider PROVIDER = new MyProvider(); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Static methods /*************************************************************************** * Create an instance of a cipher algorithm. * * @param transform * Cryptographic cipher transform, which is of the form "alg" * or "alg/pad/mode". * * @return * A cipher object of the specified type. * +REDO * @throws ... * ... * * @since 1.2, 2005-09-09 */ public static Cipher getInstance(String transform) throws NoSuchAlgorithmException, NoSuchPaddingException { /*+++INCOMPLETE ...; +++*/ throw new NoSuchAlgorithmException("INCOMPLETE"); } /*************************************************************************** * Create an instance of a cipher algorithm. * * @param alg * Cryptographic cipher algorithm name (e.g., "AES", * "IDEA", etc.). * * @param pad * Padding scheme (e.g., "NoPadding", "PKCS5Padding", * etc.); if this is empty ("") or null, a default scheme is used. * See the {@link #PADDING_NONE PADDING_XXX} constants. * * @param mode * Cryptographic operating mode (e.g., "ECB", "CBC", * "CFB", etc.); if this is empty ("") or null, a default * mode is used. * See the {@link #MODE_ECB MODE_XXX} constants. * * @return * A cipher object of the specified type. * +REDO * @throws ... * ... * * @since 1.2, 2005-09-09 */ public static Cipher getInstance(String alg, String pad, String mode) throws NoSuchAlgorithmException, NoSuchPaddingException { /*+++INCOMPLETE ...; +++*/ throw new NoSuchAlgorithmException("INCOMPLETE"); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Variables /** Name. */ String m_name = NAME; /** Version. */ double m_vers = VERSION; /** Description. */ String m_decrip = DESCRIPTION; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Constructors /*************************************************************************** * Default constructor. * * @since 1.1, 2005-04-01 */ MyProvider() { // Initialize super(NAME, VERSION, DESCRIPTION); for (int i = 0; i < ALGORITHMS.length; i++) setProperty(ALGORITHMS[i][0], ALGORITHMS[i][1]); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Methods // (None) } // End MyProvider.java