privatekeyinfo.java

来自「进行与数字证书相关开发必须的java源码」· Java 代码 · 共 85 行

JAVA
85
字号
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   PrivateKeyInfo.java

package jit.asn1.pkcs.pkcs8;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Enumeration;
import jit.asn1.*;
import jit.asn1.pkcs.PKCSObjectIdentifiers;
import jit.asn1.x509.AlgorithmIdentifier;
import jit.math.BigInteger;

public class PrivateKeyInfo
    implements PKCSObjectIdentifiers, DEREncodable
{

    private DERObject privKey;
    private AlgorithmIdentifier algId;
    private DERInteger version;
    private ASN1Set attributes;

    public PrivateKeyInfo(AlgorithmIdentifier algId, DERObject privateKey)
    {
        privKey = privateKey;
        this.algId = algId;
    }

    public PrivateKeyInfo(AlgorithmIdentifier algId, DERObject privateKey, ASN1Set attributes)
    {
        privKey = privateKey;
        this.algId = algId;
        this.attributes = attributes;
    }

    public PrivateKeyInfo(ASN1Sequence seq)
    {
        Enumeration e = seq.getObjects();
        BigInteger version = ((DERInteger)e.nextElement()).getValue();
        if(version.intValue() != 0)
            throw new IllegalArgumentException(String.valueOf(String.valueOf((new StringBuffer("wrong version:")).append(version.intValue()).append(" for private key info"))));
        algId = new AlgorithmIdentifier((ASN1Sequence)e.nextElement());
        try
        {
            ByteArrayInputStream bIn = new ByteArrayInputStream(((ASN1OctetString)e.nextElement()).getOctets());
            DERInputStream dIn = new DERInputStream(bIn);
            privKey = dIn.readObject();
        }
        catch(IOException ex)
        {
            throw new IllegalArgumentException("Error recoverying private key from sequence");
        }
        if(e.hasMoreElements())
            attributes = ASN1Set.getInstance((ASN1TaggedObject)e.nextElement(), false);
    }

    public AlgorithmIdentifier getAlgorithmId()
    {
        return algId;
    }

    public DERObject getPrivateKey()
    {
        return privKey;
    }

    public ASN1Set getAttributes()
    {
        return attributes;
    }

    public DERObject getDERObject()
    {
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(new DERInteger(0));
        v.add(algId);
        v.add(new DEROctetString(privKey));
        if(attributes != null)
            v.add(new DERTaggedObject(false, 0, attributes));
        return new DERSequence(v);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?