當前位置: 首頁>>代碼示例>>Java>>正文


Java AlgorithmParameters.getAlgorithm方法代碼示例

本文整理匯總了Java中java.security.AlgorithmParameters.getAlgorithm方法的典型用法代碼示例。如果您正苦於以下問題:Java AlgorithmParameters.getAlgorithm方法的具體用法?Java AlgorithmParameters.getAlgorithm怎麽用?Java AlgorithmParameters.getAlgorithm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.AlgorithmParameters的用法示例。


在下文中一共展示了AlgorithmParameters.getAlgorithm方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.security.AlgorithmParameters; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    PBEKeySpec ks = new PBEKeySpec(PASSWORD);
    for (int i = 0; i < PBE_ALGOS.length; i++) {
        String algo = PBE_ALGOS[i];
        SecretKeyFactory skf = SecretKeyFactory.getInstance(algo);
        SecretKey key = skf.generateSecret(ks);
        Cipher c = Cipher.getInstance(algo, "SunJCE");
        c.init(Cipher.ENCRYPT_MODE, key);
        c.doFinal(new byte[10]); // force the generation of parameters
        AlgorithmParameters params = c.getParameters();
        if (!params.getAlgorithm().equalsIgnoreCase(algo)) {
            throw new Exception("expect: " + algo +
                                ", but got: " + params.getAlgorithm());
        }
        System.out.println(algo + "...done...");
    }
    System.out.println("Test Passed");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:PBEParametersTest.java

示例2: permits

import java.security.AlgorithmParameters; //導入方法依賴的package包/類
@Override
public boolean permits(AlgorithmParameters parameters) {
    String paramAlg = parameters.getAlgorithm();
    if (!algorithm.equalsIgnoreCase(parameters.getAlgorithm())) {
        // Consider the impact of the algorithm aliases.
        Collection<String> aliases =
                AlgorithmDecomposer.getAliases(algorithm);
        if (!aliases.contains(paramAlg)) {
            return true;
        }
    }

    int keySize = KeyUtil.getKeySize(parameters);
    if (keySize == 0) {
        return false;
    } else if (keySize > 0) {
        return !((keySize < minSize) || (keySize > maxSize) ||
            (prohibitedSize == keySize));
    }   // Otherwise, the key size is not accessible or determined.
        // Conservatively, please don't disable such keys.

    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:DisabledAlgorithmConstraints.java

示例3: checkParamStrength

import java.security.AlgorithmParameters; //導入方法依賴的package包/類
private static void checkParamStrength(AlgorithmParameters param,
        DSAGenParameterSpec genParam)
        throws Exception {
    String algo = param.getAlgorithm();
    if (!algo.equalsIgnoreCase("DSA")) {
        throw new RuntimeException("Unexpected type of parameters: " + algo);
    }
    DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
    int valueL = spec.getP().bitLength();
    int strength = genParam.getPrimePLength();
    if (strength != valueL) {
        System.out.println("P: Expected " + strength + " but actual " + valueL);
        throw new RuntimeException("Wrong P strength");
    }
    int valueN = spec.getQ().bitLength();
    strength = genParam.getSubprimeQLength();
    if (strength != valueN) {
        System.out.println("Q: Expected " + strength + " but actual " + valueN);
        throw new RuntimeException("Wrong Q strength");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:TestAlgParameterGenerator.java

示例4: checkParam

import java.security.AlgorithmParameters; //導入方法依賴的package包/類
private static void checkParam(AlgorithmParameters param,
        DSAGenParameterSpec genParam) throws InvalidParameterSpecException,
                NoSuchAlgorithmException, NoSuchProviderException,
                InvalidAlgorithmParameterException {
    String algorithm = param.getAlgorithm();
    if (!algorithm.equalsIgnoreCase(ALGORITHM_NAME)) {
        throw new RuntimeException(
                "Unexpected type of parameters: " + algorithm);
    }

    DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
    int valueL = spec.getP().bitLength();
    int strengthP = genParam.getPrimePLength();
    if (strengthP != valueL) {
        System.out.printf("P: Expected %d but actual %d%n", strengthP,
                valueL);
        throw new RuntimeException("Wrong P strength");
    }

    int valueN = spec.getQ().bitLength();
    int strengthQ = genParam.getSubprimeQLength();
    if (strengthQ != valueN) {
        System.out.printf("Q: Expected %d but actual %d%n", strengthQ,
                valueN);
        throw new RuntimeException("Wrong Q strength");
    }

    if (genParam.getSubprimeQLength() != genParam.getSeedLength()) {
        System.out.println("Defaut seed length should be the same as Q.");
        throw new RuntimeException("Wrong seed length");
    }

    // use the parameters to generate real DSA keys
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME,
            PROVIDER_NAME);
    keyGen.initialize(spec);
    keyGen.generateKeyPair();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:39,代碼來源:TestDSAGenParameterSpec.java

示例5: main

import java.security.AlgorithmParameters; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        byte[] iv_1 = {
            (byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,
            (byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,
            (byte)0x33,(byte)0x33
        };

        // check that RC2 is supported by our provider
        AlgorithmParameters rc2Params =
           AlgorithmParameters.getInstance("RC2", "SunJCE");

        // check that getAlgorithm returns "RC2"
        if (!rc2Params.getAlgorithm().equals("RC2")) {
            throw new Exception("getAlgorithm() returned "
                + rc2Params.getAlgorithm() + " instead of RC2");
        }

        // test parameters with effective key size and iv
        byte[] encoded = testParams(rc2Params, new RC2ParameterSpec(2, iv_1));

        // test parameters with just iv
        encoded = testParams(AlgorithmParameters.getInstance("RC2"),
            new RC2ParameterSpec(0, iv_1));

        // test vectors in RFC 2268
        runTests(tests);
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:RC2AlgorithmParameters.java

示例6: checkParam

import java.security.AlgorithmParameters; //導入方法依賴的package包/類
private static void checkParam(AlgorithmParameters param,
        DSAGenParameterSpec genParam) throws InvalidParameterSpecException,
        NoSuchAlgorithmException, NoSuchProviderException,
        InvalidAlgorithmParameterException {
    String algorithm = param.getAlgorithm();
    if (!algorithm.equalsIgnoreCase(ALGORITHM_NAME)) {
        throw new RuntimeException(
                "Unexpected type of parameters: " + algorithm);
    }

    DSAParameterSpec spec = param.getParameterSpec(DSAParameterSpec.class);
    int valueL = spec.getP().bitLength();
    int strengthP = genParam.getPrimePLength();
    if (strengthP != valueL) {
        System.out.printf("P: Expected %d but actual %d%n", strengthP,
                valueL);
        throw new RuntimeException("Wrong P strength");
    }

    int valueN = spec.getQ().bitLength();
    int strengthQ = genParam.getSubprimeQLength();
    if (strengthQ != valueN) {
        System.out.printf("Q: Expected %d but actual %d%n", strengthQ,
                valueN);
        throw new RuntimeException("Wrong Q strength");
    }

    if (genParam.getSubprimeQLength() != genParam.getSeedLength()) {
        System.out.println("Defaut seed length should be the same as Q.");
        throw new RuntimeException("Wrong seed length");
    }

    KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM_NAME,
            PROVIDER_NAME);
    keyGen.initialize(spec);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:TestDSAGenParameterSpec.java


注:本文中的java.security.AlgorithmParameters.getAlgorithm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。