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


Java MGF1ParameterSpec類代碼示例

本文整理匯總了Java中java.security.spec.MGF1ParameterSpec的典型用法代碼示例。如果您正苦於以下問題:Java MGF1ParameterSpec類的具體用法?Java MGF1ParameterSpec怎麽用?Java MGF1ParameterSpec使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: engineGetEncoded

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
/**
 * Return the PKCS#1 ASN.1 structure RSAES-OAEP-params.
 */
protected byte[] engineGetEncoded() 
{
    AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
                                                    DigestFactory.getOID(currentSpec.getDigestAlgorithm()),
                                                    DERNull.INSTANCE);
    MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)currentSpec.getMGFParameters();
    AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
                                                    PKCSObjectIdentifiers.id_mgf1,
                                                    new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
    PSource.PSpecified      pSource = (PSource.PSpecified)currentSpec.getPSource();
    AlgorithmIdentifier pSourceAlgorithm = new AlgorithmIdentifier(
                                                    PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(pSource.getValue()));
    RSAESOAEPparams oaepP = new RSAESOAEPparams(hashAlgorithm, maskGenAlgorithm, pSourceAlgorithm);
    
    try
    {
        return oaepP.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding OAEPParameters");
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:27,代碼來源:AlgorithmParametersSpi.java

示例2: runTest

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:TestOAEPParameterSpec.java

示例3: compareMGF

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:TestOAEPParameterSpec.java

示例4: main

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
public static void main(String[] argv) throws Exception {
    boolean status = true;
    byte[] p = { (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 };
    status &= runTest("SHA-224", MGF1ParameterSpec.SHA224, p);
    status &= runTest("SHA-256", MGF1ParameterSpec.SHA256, p);
    status &= runTest("SHA-384", MGF1ParameterSpec.SHA384, p);
    status &= runTest("SHA-512", MGF1ParameterSpec.SHA512, p);
    status &= runTest("SHA", MGF1ParameterSpec.SHA1, new byte[0]);
    status &= runTest("SHA-1", MGF1ParameterSpec.SHA1, new byte[0]);
    status &= runTest("SHA1", MGF1ParameterSpec.SHA1, new byte[0]);
    if (status) {
        System.out.println("Test Passed");
    } else {
        throw new Exception("One or More Test Failed");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:TestOAEPParameterSpec.java

示例5: signPSS

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
public static byte[] signPSS(PrivateKey privateKey,
		byte[] signedData) throws SignatureException,
		InvalidKeyException, NoSuchAlgorithmException,
		NoSuchProviderException, InvalidAlgorithmParameterException {
	Signature signature = Signature.getInstance("SHA256withRSA/PSS", BC);
	signature.setParameter(new PSSParameterSpec("SHA-256", "MGF1",
			new MGF1ParameterSpec("SHA-256"), 32, 1));
	signature.initSign(privateKey);
	signature.update(signedData);
	return signature.sign();
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:12,代碼來源:RSA.java

示例6: verifyPSS

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
public static boolean verifyPSS(PublicKey publicKey,
		byte[] signedData, byte[] sig) throws SignatureException,
		InvalidKeyException, NoSuchAlgorithmException,
		NoSuchProviderException, InvalidAlgorithmParameterException, InvalidKeySpecException {
	Signature signature = Signature.getInstance("SHA256withRSA/PSS", BC);
	signature.setParameter(new PSSParameterSpec("SHA-256", "MGF1",
			new MGF1ParameterSpec("SHA-256"), 32, 1));
	signature.initVerify(publicKey);
	signature.update(signedData);
	return signature.verify(sig);
}
 
開發者ID:zsavvas,項目名稱:ReCRED_FIDO_UAF_OIDC,代碼行數:12,代碼來源:RSA.java

示例7: testGetDigestAlgorithm

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
/**
 * getDigestAlgorithm() method testing.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getDigestAlgorithm",
    args = {}
)
public void testGetDigestAlgorithm() {
    String mdName = "SHA-1";
    String mgfName = "MGF1";
    AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
    PSource pSrc = PSource.PSpecified.DEFAULT;

    OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
                                                            mgfSpec, pSrc);
    assertTrue("The returned value does not equal to the "
            + "value specified in the constructor.",
            ps.getDigestAlgorithm().equals(mdName));
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:22,代碼來源:OAEPParameterSpecTest.java

示例8: testGetMGFAlgorithm

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
/**
 * getMGFAlgorithm() method testing.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getMGFAlgorithm",
    args = {}
)
public void testGetMGFAlgorithm() {
    String mdName = "SHA-1";
    String mgfName = "MGF1";
    AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
    PSource pSrc = PSource.PSpecified.DEFAULT;

    OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
                                                            mgfSpec, pSrc);
    assertTrue("The returned value does not equal to the "
            + "value specified in the constructor.",
            ps.getMGFAlgorithm().equals(mgfName));
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:22,代碼來源:OAEPParameterSpecTest.java

示例9: testGetMGFParameters

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
/**
 * getMGFParameters() method testing.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getMGFParameters",
    args = {}
)
public void testGetMGFParameters() {
    String mdName = "SHA-1";
    String mgfName = "MGF1";
    AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
    PSource pSrc = PSource.PSpecified.DEFAULT;

    OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
                                                            mgfSpec, pSrc);
    assertTrue("The returned value does not equal to the "
            + "value specified in the constructor.",
            ps.getMGFParameters() == mgfSpec);
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:22,代碼來源:OAEPParameterSpecTest.java

示例10: testGetPSource

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
/**
 * getPSource() method testing.
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getPSource",
    args = {}
)
public void testGetPSource() {
    String mdName = "SHA-1";
    String mgfName = "MGF1";
    AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
    PSource pSrc = PSource.PSpecified.DEFAULT;

    OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName,
                                                            mgfSpec, pSrc);
    assertTrue("The returned value does not equal to the "
            + "value specified in the constructor.",
            ps.getPSource() == pSrc);
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:22,代碼來源:OAEPParameterSpecTest.java

示例11: testMGF1ParameterSpec01

import java.security.spec.MGF1ParameterSpec; //導入依賴的package包/類
/**
 * Test #1 for <code>MGF1ParameterSpec</code> constructor<br>
 * Assertion: constructs new <code>MGF1ParameterSpec</code>
 * object using valid parameter
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "MGF1ParameterSpec",
    args = {java.lang.String.class}
)
public final void testMGF1ParameterSpec01() {
    try {
        MGF1ParameterSpec pgf = new MGF1ParameterSpec(testAlgName);
        assertNotNull(pgf);
        assertTrue(pgf instanceof MGF1ParameterSpec);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:21,代碼來源:MGF1ParameterSpecTest.java


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