private KeyTransRecipientInfo computeRecipientInfo(X509Certificate x509certificate, byte[] abyte0)
     throws GeneralSecurityException, IOException {
   ASN1InputStream asn1inputstream =
       new ASN1InputStream(new ByteArrayInputStream(x509certificate.getTBSCertificate()));
   TBSCertificateStructure tbscertificatestructure =
       TBSCertificateStructure.getInstance(asn1inputstream.readObject());
   AlgorithmIdentifier algorithmidentifier =
       tbscertificatestructure.getSubjectPublicKeyInfo().getAlgorithmId();
   IssuerAndSerialNumber issuerandserialnumber =
       new IssuerAndSerialNumber(
           tbscertificatestructure.getIssuer(),
           tbscertificatestructure.getSerialNumber().getValue());
   Cipher cipher = Cipher.getInstance(algorithmidentifier.getObjectId().getId());
   cipher.init(1, x509certificate.getPublicKey());
   DEROctetString deroctetstring = new DEROctetString(cipher.doFinal(abyte0));
   RecipientIdentifier recipId = new RecipientIdentifier(issuerandserialnumber);
   return new KeyTransRecipientInfo(recipId, algorithmidentifier, deroctetstring);
 }
Exemplo n.º 2
0
 /**
  * Extracts the TBS certificate from the given certificate.
  *
  * @param cert the X.509 certificate to extract the TBS certificate from.
  * @return the TBS certificate
  * @throws IOException if extraction fails.
  * @throws CertificateEncodingException if extraction fails.
  */
 public static TBSCertificateStructure getTBSCertificateStructure(X509Certificate cert)
     throws CertificateEncodingException, IOException {
   DERObject obj = toDERObject(cert.getTBSCertificate());
   return TBSCertificateStructure.getInstance(obj);
 }