Scripting Server

CMSEnvelopedData - Reference Documentation

Class for CMS Enveloped Data handling

Index of Methods

Constructor

Prototype

CMS(ByteString encoded)

Description

Create a CMS object

Arguments

Type Name Description
ByteString encoded ASN.1 encoded bytestring containing the CMS object

Exceptions

Name Value Description
GPError GPError.GPError.INVALID_TYPE Argument type is invalid
GPError GPError.INVALID_DATA Argument contains no valid encoded CMS enveloped data object

Example


// See getContent()

getContent()

Prototype

ByteString getContent(Key privateKey, X509 recipientCertificate)

ByteString getContent(Key privateKey, ByteString subject key identifier)

Description

Return the encapsulated enveloped content as a ByteString object.

Return

ByteString Returns the encapsulated enveloped content

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


print("Generating generating key pair and X509 certificate for Recipient...\n");

var privKey = new Key();
privKey.setType(Key.PRIVATE);

var pubKey = new Key();
pubKey.setType(Key.PUBLIC);
pubKey.setSize(2048);

var crypto = new Crypto();
crypto.generateKeyPair(Crypto.RSA, pubKey, privKey);

var x = new X509CertificateGenerator(crypto);

x.reset();
x.setSerialNumber(new ByteString("01", HEX));
x.setSignatureAlgorithm(Crypto.RSA);
var issuer = { C:"UT", O:"ACME Corporation", CN:"Test-CA" };
x.setIssuer(issuer);
x.setNotBefore("060825120000Z");
x.setNotAfter("260825120000Z");
var subject = { C:"UT", O:"Utopia CA", OU:"ACME Corporation", CN:"Recipient #B" };
x.setSubject(subject);
x.setPublicKey(pubKey);
x.addKeyUsageExtension(	X509CertificateGenerator.digitalSignature |
							X509CertificateGenerator.keyCertSign |
							X509CertificateGenerator.dataEncipherment |
							X509CertificateGenerator.cRLSign );

x.addBasicConstraintsExtension(true, 0);
x.addSubjectKeyIdentifierExtension();
x.addAuthorityKeyIdentifierExtension(pubKey);

var cert = x.generateX509Certificate(privKey);

// Generate the Enveloped Data CMS object

var content = new ByteString("Hello World!", ASCII);

var gen = new CMSGenerator(CMSGenerator.TYPE_ENVELOPED_DATA);
gen.setDataContent(content);
gen.addRecipient(cert);

var envelopedData = gen.generate();

// Get the decrypted content of the Enveloped Data CMS object
// via X509 certificate

print(new ASN1(envelopedData));

var cms = new CMSEnvelopedData(envelopedData);

var result = cms.getContent(privKey, cert);

assert(content.equals(result));

// via subject key identifier

var skidList = cms.getRecipientSubjectKeyIds();

var result = cms.getContent(privKey, skidList[0]);

assert(content.equals(result));

getRecipientSubjectKeyIds()

Prototype

ByteString[] getRecipientSubjectKeyIds()

Description

Return the subject key id of all recipients of the CMS message as a bytestring

Return

ByteString[] Array containing the bytestring encoded Subject Key Identifier

Exceptions

Name Value Description
GPError GPError.INVALID_ARGUMENTS Too many arguments in call

Example


var skidList = cms.getRecipientSubjectKeyIds();
assert(skidList.length > 0);