Search in sources :

Example 6 with BIO

use of org.jruby.ext.openssl.impl.BIO in project jruby-openssl by jruby.

the class PKCS7 method decrypt.

@JRubyMethod(rest = true)
public IRubyObject decrypt(IRubyObject[] args) {
    IRubyObject dflags;
    if (Arity.checkArgumentCount(getRuntime(), args, 2, 3) == 3) {
        dflags = args[2];
    } else {
        dflags = getRuntime().getNil();
    }
    PKey pkey = (PKey) args[0];
    X509Cert cert = (X509Cert) args[1];
    final PrivateKey privKey = pkey.getPrivateKey();
    final X509AuxCertificate auxCert = cert.getAuxCert();
    final int flg = dflags.isNil() ? 0 : RubyNumeric.fix2int(dflags);
    final BIO out = BIO.mem();
    try {
        p7.decrypt(privKey, auxCert, out, flg);
    } catch (PKCS7Exception pkcs7e) {
        throw newPKCS7Error(getRuntime(), pkcs7e);
    }
    return membio2str(getRuntime(), out);
}
Also used : PrivateKey(java.security.PrivateKey) MemBIO(org.jruby.ext.openssl.impl.MemBIO) BIO(org.jruby.ext.openssl.impl.BIO) IRubyObject(org.jruby.runtime.builtin.IRubyObject) X509AuxCertificate(org.jruby.ext.openssl.x509store.X509AuxCertificate) PKCS7Exception(org.jruby.ext.openssl.impl.PKCS7Exception) NotVerifiedPKCS7Exception(org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

JRubyMethod (org.jruby.anno.JRubyMethod)6 BIO (org.jruby.ext.openssl.impl.BIO)6 MemBIO (org.jruby.ext.openssl.impl.MemBIO)6 NotVerifiedPKCS7Exception (org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception)6 PKCS7Exception (org.jruby.ext.openssl.impl.PKCS7Exception)6 IRubyObject (org.jruby.runtime.builtin.IRubyObject)5 IOException (java.io.IOException)3 Ruby (org.jruby.Ruby)3 X509AuxCertificate (org.jruby.ext.openssl.x509store.X509AuxCertificate)3 ThreadContext (org.jruby.runtime.ThreadContext)3 PrivateKey (java.security.PrivateKey)2 SMIME (org.jruby.ext.openssl.impl.SMIME)1 Store (org.jruby.ext.openssl.x509store.Store)1