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


Java Provider.getService方法代码示例

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


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

示例1: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
    if (p.getService("KeyFactory", "EC") == null) {
        System.out.println("Provider does not support EC, skipping");
        return;
    }
    int[] keyLengths = {192, 163, 409, 521};
    int len = 0;
    if (getNSSECC() == ECCState.Basic) {
        System.out.println("NSS Basic ECC only. Skipping 192, 163, & 409");
        len = 3;
    }
    KeyFactory kf = KeyFactory.getInstance("EC", p);
    for (; keyLengths.length > len ; len++) {
        System.out.println("Length "+keyLengths[len]);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", p);
        kpg.initialize(keyLengths[len]);
        KeyPair kp = kpg.generateKeyPair();
        test(kf, kp.getPrivate());
        test(kf, kp.getPublic());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TestKeyFactory.java

示例2: if

import java.security.Provider; //导入方法依赖的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. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @param algorithm the URI of the algorithm
 * @param mechanismType the type of the XML processing mechanism and
 *   representation
 * @param provider the <code>Provider</code> object
 * @return a new <code>TransformService</code>
 * @throws NullPointerException if <code>provider</code>,
 *   <code>algorithm</code>, or <code>mechanismType</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 <code>Provider</code> object
 * @see Provider
 */
public static TransformService getInstance
    (String algorithm, String mechanismType, Provider provider)
    throws NoSuchAlgorithmException {
    if (mechanismType == null || algorithm == null || provider == null) {
        throw new NullPointerException();
    }

    boolean dom = false;
    if (mechanismType.equals("DOM")) {
        dom = true;
    }
    Service s = provider.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 = provider;
                return ts;
            }
        }
    }
    throw new NoSuchAlgorithmException
        (algorithm + " algorithm and " + mechanismType
             + " mechanism not available from " + provider.getName());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:51,代码来源:TransformService.java

示例3: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
    if (p.getService("KeyFactory", "EC") == null) {
        System.out.println("Provider does not support EC, skipping");
        return;
    }
    Providers.setAt(p, 1);
    CipherTest.main(new JSSEFactory(), cmdArgs);
    Security.removeProvider(p.getName());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ClientJSSEServerJSSE.java

示例4: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyPairGenerator", "DiffieHellman") == null) {
        System.out.println("No supported of DH KeyPairGenerator, skipping");
        return;
    }

    for (UnsupportedKeySize keySize : UnsupportedKeySize.values()) {
        try {
            System.out.println("Checking " + keySize.primeSize + " ...");
            KeyPairGenerator kpg =
                    KeyPairGenerator.getInstance("DiffieHellman", provider);
            kpg.initialize(keySize.primeSize);

            throw new Exception("Should not support " + keySize.primeSize);
        } catch (InvalidParameterException ipe) {
            System.out.println("\tOk, unsupported");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:UnsupportedDHKeys.java

示例5: run

import java.security.Provider; //导入方法依赖的package包/类
@Override
void run(Provider p) throws Exception {
    if (p.getService("MessageDigest", alg) == null) {
        System.out.println("Skipped " + alg);
        return;
    }
    MessageDigest md = MessageDigest.getInstance(alg, p);
    md.update(data);
    byte[] myDigest = md.digest();
    if (Arrays.equals(digest, myDigest) == false) {
        System.out.println("Digest test for " + alg + " failed:");
        if (data.length < 256) {
            System.out.println("data: " + DigestKAT.toString(data));
        }
        System.out.println("dig:  " + DigestKAT.toString(digest));
        System.out.println("out:  " + DigestKAT.toString(myDigest));
        throw new Exception("Digest test for " + alg + " failed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:DigestKAT.java

示例6: main

import java.security.Provider; //导入方法依赖的package包/类
public void main(Provider provider) throws Exception {
    if (provider.getService(
            "KeyGenerator", "SunTlsRsaPremasterSecret") == null) {
        System.out.println("Not supported by provider, skipping");
        return;
    }
    KeyGenerator kg;
    kg = KeyGenerator.getInstance("SunTlsRsaPremasterSecret", provider);

    try {
        kg.generateKey();
        throw new Exception("no exception");
    } catch (IllegalStateException e) {
        System.out.println("OK: " + e);
    }

    int[] protocolVersions = {0x0300, 0x0301, 0x0302, 0x0400};
    for (int clientVersion : protocolVersions) {
        for (int serverVersion : protocolVersions) {
            test(kg, clientVersion, serverVersion);
            if (serverVersion >= clientVersion) {
                break;
            }
        }
    }

    System.out.println("Done.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:TestPremaster.java

示例7: getInstance

import java.security.Provider; //导入方法依赖的package包/类
/**
 * Returns an <code>XMLSignatureFactory</code> that supports the
 * requested XML processing mechanism and representation type (ex: "DOM"),
 * as supplied by the specified provider. Note that the specified
 * <code>Provider</code> object does not have to be registered in the
 * provider list.
 *
 * @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 <code>Provider</code> object
 * @return a new <code>XMLSignatureFactory</code>
 * @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 <code>Provider</code> object
 * @see Provider
 */
public static XMLSignatureFactory getInstance(String mechanismType,
    Provider provider) {
    if (mechanismType == null) {
        throw new NullPointerException("mechanismType cannot be null");
    } else if (provider == null) {
        throw new NullPointerException("provider cannot be null");
    }

    Service s = provider.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 = provider;
            return factory;
        }
    }
    throw new NoSuchMechanismException
        ("Mechanism " + mechanismType + " not available from " +
         provider.getName());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:XMLSignatureFactory.java

示例8: getInstance

import java.security.Provider; //导入方法依赖的package包/类
/**
 * Returns a <code>KeyInfoFactory</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 <a href=
 *    "{@docRoot}/../specs/security/standard-names.html#xml-signature-xmlsignaturefactorykeyinfofactorytransformservice-mechanisms">
 *    Java Security Standard Algorithm Names</a> document
 *    for more information.
 * @param provider the string name of the provider
 * @return a new <code>KeyInfoFactory</code>
 * @throws NoSuchProviderException if the specified provider is not
 *    registered in the security provider list
 * @throws NullPointerException if <code>mechanismType</code> or
 *    <code>provider</code> are <code>null</code>
 * @throws NoSuchMechanismException if a <code>KeyInfoFactory</code>
 *    implementation for the specified mechanism is not available from the
 *    specified provider
 * @see Provider
 */
public static KeyInfoFactory 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("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 from " + provider);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:KeyInfoFactory.java

示例9: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
    if (p.getService("Mac", "HmacMD5") == null) {
        System.out.println(p + " does not support HmacMD5, skipping");
        return;
    }
    Random random = new Random();
    byte[] data1 = new byte[10 * 1024];
    random.nextBytes(data1);
    byte[] keyData = new byte[16];
    random.nextBytes(keyData);
    SecretKeySpec key = new SecretKeySpec(keyData, "Hmac");
    Mac mac = Mac.getInstance("HmacMD5", p);
    mac.init(key);
    mac.init(key);
    mac.update(data1);
    mac.init(key);
    mac.doFinal();
    mac.doFinal();
    mac.update(data1);
    mac.doFinal();
    mac.reset();
    mac.reset();
    mac.init(key);
    mac.reset();
    mac.update(data1);
    mac.reset();

    System.out.println("All tests passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ReinitMac.java

示例10: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyAgreement", "ECDH") == null) {
        System.out.println("ECDH not supported, skipping");
        return;
    }

    if (isBadNSSVersion(provider)) {
        return;
    }

    kf = KeyFactory.getInstance("EC", provider);
    kpg = KeyPairGenerator.getInstance("EC", provider);

    System.out.println("Testing against NIST P-256");

    long start = System.currentTimeMillis();
    KeyPair kp256A =
        genECKeyPair("secp256r1", privD256, pubX256, pubY256, provider);
    KeyPair kp256B = genECKeyPair("secp256r1");
    testKeyAgreement(kp256A, kp256B, provider);

    System.out.println("Testing against NIST P-384");
    KeyPair kp384A =
        genECKeyPair("secp384r1", privD384, pubX384, pubY384, provider);
    KeyPair kp384B = genECKeyPair("secp384r1");
    testKeyAgreement(kp384A, kp384B, provider);

    long stop = System.currentTimeMillis();
    System.out.println("All tests passed (" + (stop - start) + " ms).");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:TestECDH2.java

示例11: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
    if (p.getService("KeyAgreement", "ECDH") == null) {
        System.out.println("Provider does not support ECDH, skipping");
        return;
    }

    if (isNSS(p) && getNSSECC() == ECCState.Basic) {
        System.out.println("NSS only supports Basic ECC.  Skipping..");
        return;
    }

    /*
     * PKCS11Test.main will remove this provider if needed
     */
    Providers.setAt(p, 1);

    if (false) {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", p);
        kpg.initialize(163);
        KeyPair kp = kpg.generateKeyPair();
        System.out.println(toString(kp.getPublic().getEncoded()));
        System.out.println(toString(kp.getPrivate().getEncoded()));
        kp = kpg.generateKeyPair();
        System.out.println(toString(kp.getPublic().getEncoded()));
        System.out.println(toString(kp.getPrivate().getEncoded()));
        return;
    }

    test(p, pub192a, priv192a, pub192b, priv192b, secret192);
    test(p, pub163a, priv163a, pub163b, priv163b, secret163);

    System.out.println("OK");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:TestECDH.java

示例12: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
    if (p.getService("KeyPairGenerator", "DH") == null) {
        System.out.println("KPG for DH not supported, skipping");
        return;
    }
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH", p);
    kpg.initialize(512);
    KeyPair kp1 = kpg.generateKeyPair();

    kpg.initialize(768);
    kp1 = kpg.generateKeyPair();

    kpg.initialize(1024);
    kp1 = kpg.generateKeyPair();

    kpg.initialize(1536);
    kp1 = kpg.generateKeyPair();

    kpg.initialize(2048);
    kp1 = kpg.generateKeyPair();

    try {
        kpg.initialize(3072);
        kp1 = kpg.generateKeyPair();

        kpg.initialize(4096);
        kp1 = kpg.generateKeyPair();

        kpg.initialize(6144);
        kp1 = kpg.generateKeyPair();

        kpg.initialize(8192);
        kp1 = kpg.generateKeyPair();
    } catch (InvalidParameterException ipe) {
        // NSS (as of version 3.13) has a hard coded maximum limit
        // of 2236 or 3072 bits for DHE keys.
        System.out.println("4096-bit DH key pair generation: " + ipe);
        if (!p.getName().equals("SunPKCS11-NSS")) {
            throw ipe;
        }
    }

    // key size must be multiples of 64 though
    checkUnsupportedKeySize(kpg, 2048 + 63);
    checkUnsupportedKeySize(kpg, 3072 + 32);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:TestDH2048.java

示例13: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider provider) throws Exception {
    long start = System.currentTimeMillis();

    if (provider.getService("Signature", "SHA1withECDSA") == null) {
        System.out.println("ECDSA not supported, skipping");
        return;
    }

    if (isBadNSSVersion(provider)) {
        return;
    }

    if (isBadSolarisSparc(provider)) {
        return;
    }

    /*
     * PKCS11Test.main will remove this provider if needed
     */
    Providers.setAt(provider, 1);

    if (false) {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", provider);
        kpg.initialize(571);
        KeyPair kp = kpg.generateKeyPair();
        PrivateKey priv = kp.getPrivate();
        ECPublicKey pub = (ECPublicKey)kp.getPublic();
        System.out.println("Keys for " + pub.getParams());
        System.out.println("public key:");
        System.out.println(toString(pub.getEncoded()));
        System.out.println("private key:");
        System.out.println(toString(priv.getEncoded()));
        return;
    }

    if (getNSSECC() != ECCState.Basic) {
        test(provider, pub192, priv192, sig192);
        test(provider, pub163, priv163, sig163);
        test(provider, pub571, priv571, sig571);
    } else {
        System.out.println("ECC Basic only, skipping 192, 163 and 571.");
    }
    test(provider, pub521, priv521, sig521);

    long stop = System.currentTimeMillis();
    System.out.println("All tests passed (" + (stop - start) + " ms).");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:TestECDSA.java

示例14: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
    if (p.getService("Signature", "SHA1withECDSA") == null) {
        System.out.println("Provider does not support ECDSA, skipping...");
        return;
    }

    if (isBadNSSVersion(p)) {
        return;
    }

    String[] names = { "secp256r1", "NIST P-192", "sect163k1", "1.3.132.0.26",
        "X9.62 c2tnb239v1"};
    int curves = 1;
    if (getNSSECC() == ECCState.Extended) {
        curves = names.length;
    }
    int[] lengths = {256, 192, 163, 233, 239};
    for (int i = 0; i < curves; i++) {
        String name = names[i];
        int len = lengths[i];
        System.out.println("Testing " + name + "...");
        ECGenParameterSpec spec = new ECGenParameterSpec(name);

        AlgorithmParameters algParams = AlgorithmParameters.getInstance("EC", p);
        algParams.init(spec);
        ECParameterSpec ecSpec = algParams.getParameterSpec(ECParameterSpec.class);
        System.out.println(ecSpec);
        // no public API to get the curve name, so rely on toString();
        if (ecSpec.toString().contains(name) == false) {
            throw new Exception("wrong curve");
        }

        algParams = AlgorithmParameters.getInstance("EC", p);
        algParams.init(ecSpec);
        ECGenParameterSpec genSpec = algParams.getParameterSpec(ECGenParameterSpec.class);
        System.out.println(genSpec.getName());

        KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", p);
        kpg.initialize(spec);
        KeyPair kp = kpg.generateKeyPair();
        System.out.println(kp.getPrivate());
        ECPublicKey publicKey = (ECPublicKey)kp.getPublic();
        if (publicKey.getParams().getCurve().getField().getFieldSize() != len) {
            throw new Exception("wrong curve");
        }
        System.out.println();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:50,代码来源:TestECGenSpec.java

示例15: main

import java.security.Provider; //导入方法依赖的package包/类
@Override
public void main(Provider p) throws Exception {
    if (p.getService("MessageDigest", "MD5") == null) {
        System.out.println("Provider does not support MD5, skipping");
        return;
    }

    Random random = new Random();
    int n = 10 * 1024;
    byte[] t = new byte[n];
    random.nextBytes(t);

    MessageDigest md = MessageDigest.getInstance("MD5", p);
    byte[] d1 = md.digest(t);

    // test 1: ByteBuffer with an accessible backing array
    ByteBuffer b1 = ByteBuffer.allocate(n + 256);
    b1.position(random.nextInt(256));
    b1.limit(b1.position() + n);
    ByteBuffer b2 = b1.slice();
    b2.put(t);
    b2.clear();
    byte[] d2 = digest(md, b2, random);
    if (Arrays.equals(d1, d2) == false) {
        throw new Exception("Test 1 failed");
    }

    // test 2: direct ByteBuffer
    ByteBuffer b3 = ByteBuffer.allocateDirect(t.length);
    b3.put(t);
    b3.clear();
    byte[] d3 = digest(md, b3, random);
    if (Arrays.equals(d1, d2) == false) {
        throw new Exception("Test 2 failed");
    }

    // test 3: ByteBuffer without an accessible backing array
    b2.clear();
    ByteBuffer b4 = b2.asReadOnlyBuffer();
    byte[] d4 = digest(md, b4, random);
    if (Arrays.equals(d1, d2) == false) {
        throw new Exception("Test 3 failed");
    }
    System.out.println("All tests passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:ByteBuffers.java


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