当前位置: 首页>>代码示例>>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;未经允许,请勿转载。