⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ijce.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            cl.getName() + error);    }    /**     * Given an algorithm name (which may be an alias) and type, returns the     * corresponding algorithm class from any provider.     */    public static Class    getImplementationClass(String algorithm, String type)    throws NoSuchAlgorithmException {        try {            return getImplementationClass(algorithm, null, type);        } catch (NoSuchProviderException e) {            throw new NoSuchAlgorithmException(e.getMessage());        }    }    /**     * Given an algorithm name (which may be an alias), a provider name, and     * a type, returns the corresponding algorithm class.     */    public static Class    getImplementationClass(String algorithm, String provider, String type)    throws NoSuchAlgorithmException, NoSuchProviderException {        String standardName = getStandardName(algorithm, type);        Class target = getClassForType(type);        if (target == null)            throw new NoSuchAlgorithmException(type + " is not a configured type");        Class cl = getClassCandidate(standardName, provider, type);        // replace this with target.isAssignableFrom(cl) for a 1.1-only release.        if (IJCE_Java10Support.isAssignableFrom(target, cl))            return cl;        throw new NoSuchAlgorithmException("class configured for " + type +            ": " + cl.getName() + " is not a subclass of " + target.getName());    }    private static Class    getClassCandidate(String standardName, String provider, String type)    throws NoSuchAlgorithmException, NoSuchProviderException {        String property = type + "." + standardName;        if (provider == null) {            String classname;            Class cl;            // the first class matching this name does not exist, so search all            // providers.            Provider[] providers = getProvidersInternal();            for (int i = 0; i < providers.length; i++) {                classname = providers[i].getProperty(property);                if (classname != null) {                    try {                        cl = findEngineClass(classname, type);                        if (cl != null)                            return cl;                    } catch (NoSuchAlgorithmException e) {}                }            }            throw new NoSuchAlgorithmException("algorithm " + standardName +                " is not available.");        }        Provider providerObj = getProviderInternal(provider);        if (providerObj == null)            throw new NoSuchProviderException("provider " + provider +                " is not available.");        String classname = providerObj.getProperty(property);        if (classname != null) {            Class cl = findEngineClass(classname, type);            if (cl != null)                return cl;        }        throw new NoSuchAlgorithmException("algorithm " + standardName +            " is not available from provider " + provider);    }    private static Class    findEngineClass(String classname, String type)    throws NoSuchAlgorithmException {        String error;        try {            return Class.forName(classname);        } catch (ClassNotFoundException e) {            return null;        } catch (NoSuchMethodError e) {            error = " does not have a zero-argument constructor.\n" + e;        } catch (LinkageError e) {            error = " could not be linked correctly.\n" + e;        }        throw new NoSuchAlgorithmException("class configured for " + type + ": " +            classname + error);    }        /**     * Returns a Target that can be passed to     * <code>PrivilegeManager.enablePrivilege(...)</code>, in order to request     * permission for an action that requires the user's trust.     * <p>     * Currently the following target names are recognized:     * <ul>     *   <li> AddSecurityProvider - add a new security provider to the system.     *   <li> RemoveSecurityProvider - remove a security provider from the system.     *   <li> SecurityPropertyRead - read the security properties.     *   <li> SecurityPropertyWrite - change the value of any security property.     *   <li> GetSecurityProviders - get a reference to any security Provider object.     * </ul>     *     * @param name  the name of the target to be returned     * @return the Target object     * @exception ForbiddenTargetException if <i>name</i> is not recognized.     */    public static Target findTarget(String name)    throws ForbiddenTargetException {        return IJCE_SecuritySupport.findTarget(name);    }    /**     * Reserved for future use, in case parameterized targets are needed. Currently     * this always throws a ForbiddenTargetException.     *     * @param name  the name of the target to be returned     * @param arg   a parameter object     * @return the Target object     * @exception ForbiddenTargetException if <i>name</i> is not recognized.     */    public static Target findTarget(String name, Object arg)    throws ForbiddenTargetException {        return IJCE_SecuritySupport.findTarget(name, arg);    }    /**     * Returns the major version of this release of IJCE.     */    public static int getMajorVersion() { return MAJOR_VERSION; }    /**     * Returns the minor version of this release of IJCE.     */    public static int getMinorVersion() { return MINOR_VERSION; }    /**     * Returns the intermediate version of this release of IJCE.     */    public static int getIntermediateVersion() { return INTER_VERSION; }    /**     * Returns true iff this version of IJCE is at least the given     * version.     */    public static boolean    isVersionAtLeast(int major, int minor, int intermediate) {        if (MAJOR_VERSION > major) return true;        if (MAJOR_VERSION < major) return false;        if (MINOR_VERSION > minor) return true;        if (MINOR_VERSION < minor) return false;        return INTER_VERSION >= intermediate;    }    /**     * Returns the release date of this version of IJCE, as a string in     * the form "yyyy/mm/dd".     */    public static String getReleaseDate() {        try {            return CVS_DATE.substring(7, 17);        } catch (StringIndexOutOfBoundsException e) {            return "unknown";        }    }    /**     * Returns a string describing this version of IJCE.     */    public static String getVersionString() {        StringBuffer version = new StringBuffer("IJCE ")            .append(MAJOR_VERSION).append(".").append(MINOR_VERSION);        if (INTER_VERSION != 0)            version.append(".").append(INTER_VERSION);        if (IS_SNAPSHOT)            version.append(" (").append(getReleaseDate()).append(" snapshot)");        return version.toString();    }    /**     * Returns true if IJCE is providing the implementations of the JCA classes     * (MessageDigest, Signature, etc). This will be false if another version     * of JCA (for example JavaSoft's) is installed earlier in the CLASSPATH.     */    public static boolean isProvidingJCA() {        try {            return IJCE_Java10Support.isAssignableFrom(                Class.forName("java.security.IJCE_Traceable"),                Class.forName("java.security.MessageDigest"));        } catch (Exception e) { return false; }    }    /**     * Returns true if IJCE is providing the implementations of the JCE classes     * (Cipher, KeyGenerator, etc). This will be false if another version     * of JCE (for example JavaSoft's) is installed earlier in the CLASSPATH.     */    public static boolean isProvidingJCE() {        try {            return IJCE_Java10Support.isAssignableFrom(                Class.forName("java.security.IJCE_Traceable"),                Class.forName("java.security.Cipher"));        } catch (Exception e) { return false; }    }// Internal methods//...........................................................................    /**     * Returns the algorithm superclass corresponding to <i>type</i>, or null     * if there is no such class.     * <p>     * For example, normally <code>getClassForType("Cipher")</code> would     * return <code>java.security.Cipher.class</code>.     * Type names are configured in the IJCE.properties file.     */    private static Class getClassForType(String type) {        Class cl = (Class) (typeToClass.get(type));        if (cl != null)            return cl;        String classname = IJCE_Properties.getProperty("Type." + type);        if (classname == null)            return null;        try {            cl = Class.forName(classname);        } catch (LinkageError e) {            IJCE.debug("Error loading class for algorithm type " + type + ": " + e);            return null;        } catch (ClassNotFoundException e) {            IJCE.debug("Error loading class for algorithm type " + type + ": " + e);            return null;        }        typeToClass.put(type, cl);        return cl;    }    /**     * Helper method to get an array of all configured security Provider objects.     * This method does not do a security check.     *     * @return an array of configured Provider objects.     */    private static Provider[] getProvidersInternal() {        try {            if (getProvidersTarget == null)                getProvidersTarget = findTarget("GetSecurityProviders");            if (privMgr == null)                privMgr = PrivilegeManager.getPrivilegeManager();                      privMgr.enablePrivilege(getProvidersTarget);        } catch (NoClassDefFoundError e) {}            Provider[] providers = Security.getProviders();        if (DEBUG && debuglevel >= 4) {            for (int i = 0; i < providers.length; i++)                debug("providers[" + i + "] = " + providers[i]);        }        try { privMgr.revertPrivilege(getProvidersTarget); }        catch (NoClassDefFoundError e) {}        return providers;    }    /**     * Helper method to get a configured security Provider object by name.     * This method does not do a security check.     *     * @return the Provider object for providerName.     */    private static Provider getProviderInternal(String providerName) {        try {            if (getProvidersTarget == null)                getProvidersTarget = findTarget("GetSecurityProviders");            if (privMgr == null)                privMgr = PrivilegeManager.getPrivilegeManager();                      privMgr.enablePrivilege(getProvidersTarget);        } catch (NoClassDefFoundError e) {}            Provider provider = Security.getProvider(providerName);        try { privMgr.revertPrivilege(getProvidersTarget); }        catch (NoClassDefFoundError e) {}        return provider;    }    /**     * Prints a debugging message that may be significant to a developer.     */    static void debug(String s) { err.println(s); }    /**     * Prints an error message that may be significant to a user.     */    static void error(String s) { err.println(s); }    /**     * Prints a "can't happen" error, with a request to report this as a bug.     * Always throws an InternalError.     */    static void reportBug(String s) {        err.println(            "\n" + s + "\n\n" +            "Please report this as a bug to <david.hopwood@lmh.ox.ac.uk>, including\n" +            "any other messages displayed on the console, and a description of what\n" +            "appeared to cause the error.\n");        throw new InternalError(s);    }    /**     * Debugging method to list all providers.     */    static void listProviders() {        Provider[] providers = getProvidersInternal();        for (int i = 0; i < providers.length; i++)            err.println("providers[" + i + "] = " + providers[i]);    }    /**     * Returns the debug level for <i>label</i>. Its value is normally given     * by the numeric provider property "<code>Debug.Level.<i>label</i></code>".     * <p>     * If this property is not set, "<code>Debug.Level.*</code>" is     * searched next. If neither property is set, or if the first property     * found is not a valid decimal integer, then this method returns 0.     */    static int getDebugLevel(String label) {        String s = IJCE_Properties.getProperty("Debug.Level." + label);        if (s == null) {            s = IJCE_Properties.getProperty("Debug.Level.*");            if (s == null)                return 0;        }        try { return Integer.parseInt(s); }        catch (NumberFormatException e) { return 0; }    }    /**     * Returns the PrintWriter that debugging Output is to be sent to.     */    static PrintWriter getDebugOutput() {        return err;    }// Main//...........................................................................    /**     * Prints the IJCE version string, a list of statically configured providers,     * and the location of the library directory.     */    public static void main(String[] args) {        System.out.println(getVersionString());        System.out.println();        listProviders();        System.out.println();        try {            String libPath = IJCE_Properties.getLibraryPath();            System.out.println("The library directory is");            System.out.println("  " + libPath);        } catch (IOException e) {            e.printStackTrace();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -