Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
BEGIN LICENSE BLOCK ***** Version: CPL 1.0/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Common Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Copyright (C) 2008 Ola Bini <> Alternatively, the contents of this file may be used under the terms of either of the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the CPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the CPL, the GPL or the LGPL. END LICENSE BLOCK ***
 package org.jruby.ext.openssl.impl;
 import  org.bouncycastle.asn1.ASN1Encodable;
 import  org.bouncycastle.asn1.ASN1EncodableVector;
 import  org.bouncycastle.asn1.ASN1InputStream;
 import  org.bouncycastle.asn1.ASN1OctetString;
 import  org.bouncycastle.asn1.DEREncodable;
 import  org.bouncycastle.asn1.DERInteger;
 import  org.bouncycastle.asn1.DERSequence;
 import  org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber;
 import  org.bouncycastle.asn1.x509.AlgorithmIdentifier;
 import  org.bouncycastle.asn1.x509.X509Name;

Ola Bini
 public class RecipInfo {
     private int version;
     private IssuerAndSerialNumber issuerAndSerial;
     private AlgorithmIdentifier keyEncAlgor;
     private ASN1OctetString encKey;

Describe cert here.
     private X509AuxCertificate cert;

     public void set(X509AuxCertificate certthrows PKCS7Exception {
          = 0;
         try {
             X509Name issuer = X509Name.getInstance(new ASN1InputStream(new ByteArrayInputStream(cert.getIssuerX500Principal().getEncoded())).readObject());
             BigInteger serial = cert.getSerialNumber();
              = new IssuerAndSerialNumber(issuerserial);
             String algo = addEncryptionIfNeeded(cert.getPublicKey().getAlgorithm());
              = new AlgorithmIdentifier(ASN1Registry.sym2oid(algo));
             this. = cert;
         } catch(IOException e) {
             throw new PKCS7Exception(-1, -1, e);
     private String addEncryptionIfNeeded(String input) {
         input = input.toLowerCase();
         if(input.equals("rsa")) {
             return input + "Encryption";
         } else if(input.equals("dsa")) {
             return input + "Encryption";
         return input;
     public boolean equals(Object other) {
         boolean ret = this == other;
         if(!ret && (other instanceof RecipInfo)) {
             RecipInfo o = (RecipInfo)other;
             ret = 
                 this. == o.version &&
                 (this. == null ? o.issuerAndSerial == null : (this..equals(o.issuerAndSerial))) &&
                 (this. == null ? o.keyEncAlgor == null : (this..equals(o.keyEncAlgor))) &&
                 (this. == null ? o.encKey == null : (this..equals(o.encKey)));
        return ret;
    public int hashCode() {
        int result = 31;
        result = result + 13 * ;
        result = result + (( == null) ? 0 : 13 * .hashCode());
        result = result + (( == null) ? 0 : 13 * .hashCode());
        result = result + (( == null) ? 0 : 13 * .hashCode());
        return result;
    public String toString() {
        return "#<Recipient version="++" issuerAndSerial=["+.getName()+","+.getCertificateSerialNumber()+"] keyEncAlgor="+ASN1Registry.o2a(.getObjectId())+" encKey="++">";

Get the Version value.

an int value
    public final int getVersion() {
        return ;

Set the Version value.

newVersion The new Version value.
    public final void setVersion(final int newVersion) {
        this. = newVersion;

Get the IssuerAndSerial value.

an IssuerAndSerialNumber value
    public final IssuerAndSerialNumber getIssuerAndSerial() {
        return ;

Set the IssuerAndSerial value.

newIssuerAndSerial The new IssuerAndSerial value.
    public final void setIssuerAndSerial(final IssuerAndSerialNumber newIssuerAndSerial) {
        this. = newIssuerAndSerial;

Get the KeyEncAlgor value.

an AlgorithmIdentifier value
    public final AlgorithmIdentifier getKeyEncAlgor() {
        return ;

Set the KeyEncAlgor value.

newKeyEncAlgor The new KeyEncAlgor value.
    public final void setKeyEncAlgor(final AlgorithmIdentifier newKeyEncAlgor) {
        this. = newKeyEncAlgor;

Get the EncKey value.

an ASN1OctetString value
    public final ASN1OctetString getEncKey() {
        return ;

Set the EncKey value.

newEncKey The new EncKey value.
    public final void setEncKey(final ASN1OctetString newEncKey) {
        this. = newEncKey;

Get the Cert value.

a X509AuxCertificate value
    public final X509AuxCertificate getCert() {
        return ;

Set the Cert value.

newCert The new Cert value.
    public final void setCert(final X509AuxCertificate newCert) {
        this. = newCert;
    /* c: static pkcs7_cmp_ri
    public boolean compare(X509AuxCertificate pcert) {
        if(!new Name(.getName()).isEqual(pcert.getIssuerX500Principal())) {
            return false;
        return pcert.getSerialNumber().compareTo(.getCertificateSerialNumber().getValue()) == 0;

RecipientInfo ::= SEQUENCE { version Version, issuerAndSerialNumber IssuerAndSerialNumber, keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier, encryptedKey EncryptedKey } EncryptedKey ::= OCTET STRING
    public static RecipInfo fromASN1(DEREncodable content) {
        DERSequence sequence = (DERSequence)content;
        RecipInfo ri = new RecipInfo();
        return ri;
    public ASN1Encodable asASN1() {
        ASN1EncodableVector vector = new ASN1EncodableVector();
        vector.add(new DERInteger(getVersion()));
        return new DERSequence(vector);
}// RecipInfo
New to GrepCode? Check out our FAQ X