载入BC:
...
Security.addProvider(new BouncyCastleProvider());
...
组数字信封:
public byte[] envelope(byte[] data, String certPath) throws Exception {
CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509", "BC");
FileInputStream bais = new FileInputStream(certPath);
X509Certificate cert = (X509Certificate) certificatefactory.generateCertificate(bais);
CMSTypedData msg = new CMSProcessableByteArray(data);
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(cert).setProvider("BC"));
CMSEnvelopedData ed = edGen.generate(msg, new JceCMSContentEncryptorBuilder(PKCSObjectIdentifiers.rc4).setProvider("BC").build());
byte[] result = ed.getEncoded();
return result;
}
解数字信封