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


Java NetscapeCertRequest類代碼示例

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


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

示例1: perform

import org.bouncycastle.jce.netscape.NetscapeCertRequest; //導入依賴的package包/類
public TestResult perform()
{
    try
    {
        String    challenge = "fixed-for-now";
    
        byte data [] = Base64.decode (test1);

        ASN1InputStream    in = new ASN1InputStream (new ByteArrayInputStream(data));
        ASN1Sequence    spkac = (ASN1Sequence)in.readObject ();
        // System.out.println("SPKAC: \n"+DERDump.dumpAsString (spkac));


        NetscapeCertRequest nscr = new NetscapeCertRequest (spkac);

        if (!nscr.verify (challenge)) 
        {
            return new SimpleTestResult(false, getName() + ": 1 - not verified");
        }

        //now try to generate one
        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance (nscr.getKeyAlgorithm().getObjectId ().getId(), "BC");

        kpg.initialize (1024);

        KeyPair kp = kpg.genKeyPair();

        nscr.setPublicKey (kp.getPublic());
        nscr.sign (kp.getPrivate());
        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DEROutputStream deros = new DEROutputStream (baos);
        deros.writeObject (nscr);
        deros.close();

        
        ASN1InputStream     in2 =
            new ASN1InputStream (new ByteArrayInputStream(baos.toByteArray()));
        ASN1Sequence        spkac2 = (ASN1Sequence)in2.readObject ();

        // System.out.println("SPKAC2: \n"+DERDump.dumpAsString (spkac2));

        NetscapeCertRequest nscr2 = new NetscapeCertRequest (spkac2);

        if (!nscr2.verify (challenge)) 
        {
            return new SimpleTestResult(false, getName() + ": 2 - not verified");
        }

        //lets build it from scratch


        challenge = "try it";

        NetscapeCertRequest nscr3 =
            new NetscapeCertRequest (challenge,
                                     new AlgorithmIdentifier(PKCSObjectIdentifiers.sha1WithRSAEncryption, null),
                                     kp.getPublic());
        
        nscr3.sign (kp.getPrivate());
        
        // System.out.println("SPKAC3: \n"+DERDump.dumpAsString (nscr3));
        
        if (nscr3.verify (challenge)) 
        {
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        else
        {
            return new SimpleTestResult(false, getName() + ": 3 - not verified");
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": exception - " + e.toString());
    }
}
 
開發者ID:NoYouShutup,項目名稱:CryptMeme,代碼行數:79,代碼來源:NetscapeCertRequestTest.java

示例2: perform

import org.bouncycastle.jce.netscape.NetscapeCertRequest; //導入依賴的package包/類
public TestResult perform()
{
    try
    {
        String    challenge = "fixed-for-now";
    
        byte data [] = Base64.decode (test1);

        ASN1InputStream    in = new ASN1InputStream (new ByteArrayInputStream(data));
        ASN1Sequence    spkac = (ASN1Sequence)in.readObject ();
        // System.out.println("SPKAC: \n"+DERDump.dumpAsString (spkac));


        NetscapeCertRequest nscr = new NetscapeCertRequest (spkac);

        if (!nscr.verify (challenge)) 
        {
            return new SimpleTestResult(false, getName() + ": 1 - not verified");
        }

        //now try to generate one
        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance (nscr.getKeyAlgorithm().getObjectId ().getId(), "BC");

        kpg.initialize (1024);

        KeyPair kp = kpg.generateKeyPair();

        nscr.setPublicKey (kp.getPublic());
        nscr.sign (kp.getPrivate());
        
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DEROutputStream deros = new DEROutputStream (baos);
        deros.writeObject (nscr);
        deros.close();

        
        ASN1InputStream    in2 =
            new ASN1InputStream (new ByteArrayInputStream(baos.toByteArray()));
        ASN1Sequence    spkac2 = (ASN1Sequence)in2.readObject ();

        // System.out.println("SPKAC2: \n"+DERDump.dumpAsString (spkac2));

        NetscapeCertRequest nscr2 = new NetscapeCertRequest (spkac2);

        if (!nscr2.verify (challenge)) 
        {
            return new SimpleTestResult(false, getName() + ": 2 - not verified");
        }

        //lets build it from scratch


        challenge = "try it";

        NetscapeCertRequest nscr3 =
            new NetscapeCertRequest (challenge,
                                     new AlgorithmIdentifier(PKCSObjectIdentifiers.sha1WithRSAEncryption, null),
                                     kp.getPublic());
        
        nscr3.sign (kp.getPrivate());
        
        // System.out.println("SPKAC3: \n"+DERDump.dumpAsString (nscr3));
        
        if (nscr3.verify (challenge)) 
        {
            return new SimpleTestResult(true, getName() + ": Okay");
        }
        else
        {
            return new SimpleTestResult(false, getName() + ": 3 - not verified");
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": exception - " + e.toString());
    }
}
 
開發者ID:credentials,項目名稱:irma_future_id,代碼行數:79,代碼來源:NetscapeCertRequestTest.java


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