List of usage examples for org.bouncycastle.asn1.cms CMSObjectIdentifiers compressedData
ASN1ObjectIdentifier compressedData
To view the source code for org.bouncycastle.asn1.cms CMSObjectIdentifiers compressedData.
Click Source Link
From source file:es.gob.afirma.applet.CMSInformation.java
License:Open Source License
/** * Método principal que obtiene la información a partir de un fichero firmado * de tipo CMS./*from www . j a v a 2 s. co m*/ * @param data Objeto CMS. * @return Texto descriptivo del objeto CMS. * @throws IOException Si ocurre algún problema leyendo o escribiendo los datos * @throws AOInvalidFormatException Error de formato no válido. */ static String getInformation(final byte[] data) throws IOException, AOInvalidFormatException { final ASN1InputStream is = new ASN1InputStream(data); // LEEMOS EL FICHERO QUE NOS INTRODUCEN final ASN1Sequence dsq = (ASN1Sequence) is.readObject(); is.close(); final Enumeration<?> e = dsq.getObjects(); // Elementos que contienen los elementos OID Data final ASN1ObjectIdentifier doi = (ASN1ObjectIdentifier) e.nextElement(); // Contenido a obtener informacion final ASN1TaggedObject doj = (ASN1TaggedObject) e.nextElement(); final String datos; if (doi.equals(PKCSObjectIdentifiers.data)) { datos = AppletMessages.getString("CMSInformation.0") + SP + DATA + CR; //$NON-NLS-1$ } else if (doi.equals(PKCSObjectIdentifiers.digestedData)) { datos = getFromDigestedData(doj); } else if (doi.equals(PKCSObjectIdentifiers.encryptedData)) { datos = extractData(doj, TYPE_ENCRYPTED_DATA, AppletMessages.getString("CMSInformation.0") + SP + ENCRYPTED_DATA, BINARY_SIGN_CMS); //$NON-NLS-1$ } else if (doi.equals(PKCSObjectIdentifiers.signedData)) { datos = extractData(doj, TYPE_SIGNED_DATA, AppletMessages.getString("CMSInformation.0") + SP + SIGNED_DATA, BINARY_SIGN_CMS); //$NON-NLS-1$ } else if (doi.equals(PKCSObjectIdentifiers.envelopedData)) { datos = extractData(doj, TYPE_ENVELOPED_DATA, AppletMessages.getString("CMSInformation.0") + SP + ENVELOPED_DATA, BINARY_SIGN_CMS); //$NON-NLS-1$ } else if (doi.equals(PKCSObjectIdentifiers.signedAndEnvelopedData)) { datos = extractData(doj, TYPE_SIGNED_ENVELOPED_DATA, AppletMessages.getString("CMSInformation.0") + SP + SIGNED_ENVELOPED_DATA, BINARY_SIGN_CMS); //$NON-NLS-1$ } else if (doi.equals(PKCSObjectIdentifiers.id_ct_authData)) { datos = extractData(doj, TYPE_AUTHENTICATED_DATA, AppletMessages.getString("CMSInformation.0") + SP + AUTHENTICATED_DATA, BINARY_SIGN_CMS); //$NON-NLS-1$ } else if (doi.equals(PKCSObjectIdentifiers.id_ct_authEnvelopedData)) { datos = extractData(doj, TYPE_AUTHENTICATED_ENVELOPED_DATA, AppletMessages.getString("CMSInformation.0") + SP + AUTH_ENVELOPED_DATA, BINARY_SIGN_CMS); //$NON-NLS-1$ } else if (doi.equals(CMSObjectIdentifiers.compressedData)) { datos = getFromCompressedData(doj); } else { throw new AOInvalidFormatException( "Los datos introducidos no se corresponden con un tipo de objeto CMS soportado"); //$NON-NLS-1$ } return datos; }
From source file:es.gob.afirma.envelopers.cms.CMSCompressedData.java
License:Open Source License
/** Obtiene un tipo CompressedData. * @param data/*from w w w .j ava2s . c o m*/ * Datos a comprimir * @return Tipo CompressedData. * @throws IOException En caso de error en la lectura o tratamiento de datos */ static byte[] genCompressedData(final byte[] data) throws IOException { // Algoritmo de compresion final AlgorithmIdentifier comAlgId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(ZLIB)); // Se comprimen los datos final byte[] compressed = BinaryUtils.compress(data); final ASN1OctetString comOcts = new BEROctetString(compressed); // Contenido comprimido final ContentInfo comContent = new ContentInfo(CMSObjectIdentifiers.data, comOcts); return new ContentInfo(CMSObjectIdentifiers.compressedData, new CompressedData(comAlgId, comContent)) .getEncoded(ASN1Encoding.DER); }
From source file:es.gob.afirma.envelopers.cms.ValidateCMS.java
License:Open Source License
/** Método que verifica que es una firma de tipo "CompressedData" * @param data/*from w w w.ja va 2 s . c om*/ * Datos CMS. * @return si es de este tipo. */ static boolean isCMSCompressedData(final byte[] data) { boolean isValid = true; try { // Leemos el fichero que contiene la firma. final ASN1InputStream is = new ASN1InputStream(data); // Comenzamos a obtener los datos. final ASN1Sequence dsq = (ASN1Sequence) is.readObject(); is.close(); final Enumeration<?> e = dsq.getObjects(); // Elementos que contienen los elementos OID CompressedData. final ASN1ObjectIdentifier doi = (ASN1ObjectIdentifier) e.nextElement(); if (!doi.equals(CMSObjectIdentifiers.compressedData)) { isValid = false; } else { // Contenido de CompressedData final ASN1TaggedObject doj = (ASN1TaggedObject) e.nextElement(); final ASN1Sequence compressedData = (ASN1Sequence) doj.getObject(); CompressedData.getInstance(compressedData); } } catch (final Exception ex) { isValid = false; } return isValid; }
From source file:mitm.common.security.cms.CMSContentTypeClassifier.java
License:Open Source License
/** * Returns the CMS content type of the provided sequence. * //from ww w. jav a 2 s . com * See RFC3852 for content types * * @param sequenceParser * @return */ public static CMSContentType getContentType(ASN1SequenceParser sequenceParser) { CMSContentType contentType = CMSContentType.UNKNOWN; try { ContentInfoParser contentInfoParser = new ContentInfoParser(sequenceParser); DERObjectIdentifier derContentType = contentInfoParser.getContentType(); if (CMSObjectIdentifiers.data.equals(derContentType)) { contentType = CMSContentType.DATA; } else if (CMSObjectIdentifiers.signedData.equals(derContentType)) { contentType = CMSContentType.SIGNEDDATA; } else if (CMSObjectIdentifiers.envelopedData.equals(derContentType)) { contentType = CMSContentType.ENVELOPEDDATA; } else if (CMSObjectIdentifiers.signedAndEnvelopedData.equals(derContentType)) { contentType = CMSContentType.SIGNEDANDENVELOPEDDATA; } else if (CMSObjectIdentifiers.digestedData.equals(derContentType)) { contentType = CMSContentType.DIGESTEDDATA; } else if (CMSObjectIdentifiers.encryptedData.equals(derContentType)) { contentType = CMSContentType.ENCRYPTEDDATA; } else if (CMSObjectIdentifiers.compressedData.equals(derContentType)) { contentType = CMSContentType.COMPRESSEDDATA; } } catch (IOException e) { logger.error("IOException retrieving CMS content type", e); } return contentType; }