当前位置: 首页>>代码示例>>Java>>正文


Java Service.newInstance方法代码示例

本文整理汇总了Java中java.security.Provider.Service.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Service.newInstance方法的具体用法?Java Service.newInstance怎么用?Java Service.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.Provider.Service的用法示例。


在下文中一共展示了Service.newInstance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newInstance

import java.security.Provider.Service; //导入方法依赖的package包/类
private static SignatureSpi newInstance(Service s)
        throws NoSuchAlgorithmException {
    if (s.getType().equals("Cipher")) {
        // must be NONEwithRSA
        try {
            Cipher c = Cipher.getInstance(RSA_CIPHER, s.getProvider());
            return new CipherAdapter(c);
        } catch (NoSuchPaddingException e) {
            throw new NoSuchAlgorithmException(e);
        }
    } else {
        Object o = s.newInstance(null);
        if (o instanceof SignatureSpi == false) {
            throw new NoSuchAlgorithmException
                ("Not a SignatureSpi: " + o.getClass().getName());
        }
        return (SignatureSpi)o;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:Signature.java

示例2: if

import java.security.Provider.Service; //导入方法依赖的package包/类
/**
 * Returns a <code>TransformService</code> that supports the specified
 * algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
 * (ex: DOM) as supplied by the specified provider. The specified provider
 * must be registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the string name of the provider
 * @return a new <code>TransformService</code>
 * @throws NoSuchProviderException if the specified provider is not
 *   registered in the security provider list
 * @throws NullPointerException if <code>provider</code>,
 *   <code>mechanismType</code>, or <code>algorithm</code> is
 *   <code>null</code>
 * @throws NoSuchAlgorithmException if a <code>TransformService</code>
 *   implementation for the specified algorithm and mechanism type is not
 *   available from the specified provider
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }
    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Provider p = Security.getProvider(provider);
    if (p == null) {
        throw new NoSuchProviderException("No such provider: " +
                                          provider);
    }
    Service s = p.getService("TransformService", algorithm);
    if (s != null) {
        String value = s.getAttribute("MechanismType");
        if ((value == null && dom) ||
            (value != null && value.equals(mechanismType))) {
            Object obj = s.newInstance(null);
            if (obj instanceof TransformService) {
                TransformService ts = (TransformService) obj;
                ts.algorithm = algorithm;
                ts.mechanism = mechanismType;
                ts.provider = p;
                return ts;
            }
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available from " + provider);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:TransformService.java

示例3: loadFactory

import java.security.Provider.Service; //导入方法依赖的package包/类
private static Object loadFactory(Service service)
    throws SaslException {
    try {
        /*
         * Load the implementation class with the same class loader
         * that was used to load the provider.
         * In order to get the class loader of a class, the
         * caller's class loader must be the same as or an ancestor of
         * the class loader being returned. Otherwise, the caller must
         * have "getClassLoader" permission, or a SecurityException
         * will be thrown.
         */
        return service.newInstance(null);
    } catch (InvalidParameterException | NoSuchAlgorithmException e) {
        throw new SaslException("Cannot instantiate service " + service, e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:Sasl.java

示例4: isSpi

import java.security.Provider.Service; //导入方法依赖的package包/类
private static boolean isSpi(Service s) {
    if (s.getType().equals("Cipher")) {
        // must be a CipherSpi, which we can wrap with the CipherAdapter
        return true;
    }
    String className = s.getClassName();
    Boolean result = signatureInfo.get(className);
    if (result == null) {
        try {
            Object instance = s.newInstance(null);
            // Signature extends SignatureSpi
            // so it is a "real" Spi if it is an
            // instance of SignatureSpi but not Signature
            boolean r = (instance instanceof SignatureSpi)
                            && (instance instanceof Signature == false);
            if ((debug != null) && (r == false)) {
                debug.println("Not a SignatureSpi " + className);
                debug.println("Delayed provider selection may not be "
                    + "available for algorithm " + s.getAlgorithm());
            }
            result = Boolean.valueOf(r);
            signatureInfo.put(className, result);
        } catch (Exception e) {
            // something is wrong, assume not an SPI
            return false;
        }
    }
    return result.booleanValue();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:Signature.java

示例5: getInstance

import java.security.Provider.Service; //导入方法依赖的package包/类
/**
 * Returns an <code>XMLSignatureFactory</code> that supports the
 * requested XML processing mechanism and representation type (ex: "DOM"),
 * as supplied by the specified provider. The specified provider must be
 * registered in the security provider list.
 *
 * <p>Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param mechanismType the type of the XML processing mechanism and
 *    representation. See the {@extLink security_guide_xmldsig_provider
 *    Service Providers} section of the API overview for a list of
 *    standard mechanism types.
 * @param provider the string name of the provider
 * @return a new <code>XMLSignatureFactory</code>
 * @throws NoSuchProviderException if the specified provider is not
 *    registered in the security provider list
 * @throws NullPointerException if <code>provider</code> or
 *    <code>mechanismType</code> is <code>null</code>
 * @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
 *    implementation for the specified mechanism is not
 *    available from the specified provider
 * @see Provider
 */
public static XMLSignatureFactory getInstance(String mechanismType,
    String provider) throws NoSuchProviderException {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    } else if (provider.length() == 0) {
        throw new NoSuchProviderException();
    }

    Provider p = Security.getProvider(provider);
    if (p == null) {
        throw new NoSuchProviderException("No such provider: " +
                                          provider);
    }
    Service s = p.getService("XMLSignatureFactory", mechanismType);
    if (s != null) {
        Object obj = null;
        try {
            obj = s.newInstance(null);
        } catch (NoSuchAlgorithmException nsae) {
            throw new NoSuchMechanismException(nsae);
        }
        if (obj instanceof XMLSignatureFactory) {
            XMLSignatureFactory factory = (XMLSignatureFactory) obj;
            factory.mechanismType = mechanismType;
            factory.provider = p;
            return factory;
        }
    }
    throw new NoSuchMechanismException
        ("Mechanism " + mechanismType + " not available from " + provider);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:XMLSignatureFactory.java

示例6: getInstance

import java.security.Provider.Service; //导入方法依赖的package包/类
/**
 * Returns a <code>KeyInfoFactory</code> that supports the
 * specified XML processing mechanism and representation type (ex: "DOM").
 *
 * <p>This method uses the standard JCA provider lookup mechanism to
 * locate and instantiate a <code>KeyInfoFactory</code> implementation of
 * the desired mechanism type. It traverses the list of registered security
 * <code>Provider</code>s, starting with the most preferred
 * <code>Provider</code>. A new <code>KeyInfoFactory</code> object
 * from the first <code>Provider</code> that supports the specified
 * mechanism is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @implNote
 * The JDK Reference Implementation additionally uses the
 * {@code jdk.security.provider.preferred}
 * {@link Security#getProperty(String) Security} property to determine
 * the preferred provider order for the specified algorithm. This
 * may be different than the order of providers returned by
 * {@link Security#getProviders() Security.getProviders()}.
 *
 * @param mechanismType the type of the XML processing mechanism and
 *    representation.  See the <a href=
 *    "{@docRoot}/../specs/security/standard-names.html#xml-signature-xmlsignaturefactorykeyinfofactorytransformservice-mechanisms">
 *    Java Security Standard Algorithm Names</a> document
 * for more information.
 * @return a new <code>KeyInfoFactory</code>
 * @throws NullPointerException if <code>mechanismType</code> is
 *    <code>null</code>
 * @throws NoSuchMechanismException if no <code>Provider</code> supports a
 *    <code>KeyInfoFactory</code> implementation for the specified mechanism
 * @see Provider
 */
public static KeyInfoFactory getInstance(String mechanismType) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    }
    Provider[] provs = Security.getProviders();
    for (Provider p : provs) {
        Service s = p.getService("KeyInfoFactory", mechanismType);
        if (s != null) {
            Object obj = null;
            try {
                obj = s.newInstance(null);
            } catch (NoSuchAlgorithmException nsae) {
                throw new NoSuchMechanismException(nsae);
            }
            if (obj instanceof KeyInfoFactory) {
                KeyInfoFactory factory = (KeyInfoFactory) obj;
                factory.mechanismType = mechanismType;
                factory.provider = p;
                return factory;
            }
        }
    }
    throw new NoSuchMechanismException
        ("Mechanism " + mechanismType + " not available");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:KeyInfoFactory.java

示例7: getInstance

import java.security.Provider.Service; //导入方法依赖的package包/类
public static Instance getInstance(Service s, Class<?> clazz)
        throws NoSuchAlgorithmException {
    Object instance = s.newInstance(null);
    checkSuperClass(s, instance.getClass(), clazz);
    return new Instance(s.getProvider(), instance);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:GetInstance.java

示例8: getInstance

import java.security.Provider.Service; //导入方法依赖的package包/类
/**
 * Returns a <code>Cipher</code> object that implements the specified
 * transformation.
 *
 * <p> This method traverses the list of registered security Providers,
 * starting with the most preferred Provider.
 * A new Cipher object encapsulating the
 * CipherSpi implementation from the first
 * Provider that supports the specified algorithm is returned.
 *
 * <p> Note that the list of registered providers may be retrieved via
 * the {@link Security#getProviders() Security.getProviders()} method.
 *
 * @param transformation the name of the transformation, e.g.,
 * <i>DES/CBC/PKCS5Padding</i>.
 * See the Cipher section in the <a href=
 *   "{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">
 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 * for information about standard transformation names.
 *
 * @return a cipher that implements the requested transformation.
 *
 * @exception NoSuchAlgorithmException if <code>transformation</code>
 *          is null, empty, in an invalid format,
 *          or if no Provider supports a CipherSpi implementation for the
 *          specified algorithm.
 *
 * @exception NoSuchPaddingException if <code>transformation</code>
 *          contains a padding scheme that is not available.
 *
 * @see java.security.Provider
 */
public static final Cipher getInstance(String transformation)
        throws NoSuchAlgorithmException, NoSuchPaddingException
{
    List<Transform> transforms = getTransforms(transformation);
    List<ServiceId> cipherServices = new ArrayList<>(transforms.size());
    for (Transform transform : transforms) {
        cipherServices.add(new ServiceId("Cipher", transform.transform));
    }
    List<Service> services = GetInstance.getServices(cipherServices);
    // make sure there is at least one service from a signed provider
    // and that it can use the specified mode and padding
    Iterator<Service> t = services.iterator();
    Exception failure = null;
    while (t.hasNext()) {
        Service s = t.next();
        if (JceSecurity.canUseProvider(s.getProvider()) == false) {
            continue;
        }
        Transform tr = getTransform(s, transforms);
        if (tr == null) {
            // should never happen
            continue;
        }
        int canuse = tr.supportsModePadding(s);
        if (canuse == S_NO) {
            // does not support mode or padding we need, ignore
            continue;
        }
        if (canuse == S_YES) {
            return new Cipher(null, s, t, transformation, transforms);
        } else { // S_MAYBE, try out if it works
            try {
                CipherSpi spi = (CipherSpi)s.newInstance(null);
                tr.setModePadding(spi);
                return new Cipher(spi, s, t, transformation, transforms);
            } catch (Exception e) {
                failure = e;
            }
        }
    }
    throw new NoSuchAlgorithmException
        ("Cannot find any provider supporting " + transformation, failure);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:76,代码来源:Cipher.java

示例9: getInstance

import java.security.Provider.Service; //导入方法依赖的package包/类
public static Instance getInstance(Service s, Class<?> clazz,
        Object param) throws NoSuchAlgorithmException {
    Object instance = s.newInstance(param);
    checkSuperClass(s, instance.getClass(), clazz);
    return new Instance(s.getProvider(), instance);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:GetInstance.java

示例10: chooseProvider

import java.security.Provider.Service; //导入方法依赖的package包/类
private void chooseProvider(int initType, int opmode, Key key,
        AlgorithmParameterSpec paramSpec,
        AlgorithmParameters params, SecureRandom random)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    synchronized (lock) {
        if (spi != null) {
            implInit(spi, initType, opmode, key, paramSpec, params, random);
            return;
        }
        Exception lastException = null;
        while ((firstService != null) || serviceIterator.hasNext()) {
            Service s;
            CipherSpi thisSpi;
            if (firstService != null) {
                s = firstService;
                thisSpi = firstSpi;
                firstService = null;
                firstSpi = null;
            } else {
                s = serviceIterator.next();
                thisSpi = null;
            }
            // if provider says it does not support this key, ignore it
            if (s.supportsParameter(key) == false) {
                continue;
            }
            if (JceSecurity.canUseProvider(s.getProvider()) == false) {
                continue;
            }
            Transform tr = getTransform(s, transforms);
            if (tr == null) {
                // should never happen
                continue;
            }
            if (tr.supportsModePadding(s) == S_NO) {
                continue;
            }
            try {
                if (thisSpi == null) {
                    thisSpi = (CipherSpi)s.newInstance(null);
                }
                tr.setModePadding(thisSpi);
                initCryptoPermission();
                implInit(thisSpi, initType, opmode, key, paramSpec,
                                                    params, random);
                provider = s.getProvider();
                this.spi = thisSpi;
                firstService = null;
                serviceIterator = null;
                transforms = null;
                return;
            } catch (Exception e) {
                // NoSuchAlgorithmException from newInstance()
                // InvalidKeyException from init()
                // RuntimeException (ProviderException) from init()
                // SecurityException from crypto permission check
                if (lastException == null) {
                    lastException = e;
                }
            }
        }
        // no working provider found, fail
        if (lastException instanceof InvalidKeyException) {
            throw (InvalidKeyException)lastException;
        }
        if (lastException instanceof InvalidAlgorithmParameterException) {
            throw (InvalidAlgorithmParameterException)lastException;
        }
        if (lastException instanceof RuntimeException) {
            throw (RuntimeException)lastException;
        }
        String kName = (key != null) ? key.getClass().getName() : "(null)";
        throw new InvalidKeyException
            ("No installed provider supports this key: "
            + kName, lastException);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:78,代码来源:Cipher.java


注:本文中的java.security.Provider.Service.newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。