Ejemplo n.º 1
0
 @Override
 public byte[] getBytes() throws DSSException {
   final InputStream inputStream = openStream();
   final byte[] bytes = DSSUtils.toByteArray(inputStream);
   IOUtils.closeQuietly(inputStream);
   return bytes;
 }
Ejemplo n.º 2
0
 @Override
 public String getBase64Encoded() {
   final InputStream inputStream = openStream();
   final byte[] bytes = DSSUtils.toByteArray(inputStream);
   IOUtils.closeQuietly(inputStream);
   return Base64.encodeBase64String(bytes);
 }
Ejemplo n.º 3
0
 @Override
 public String getDigest(final DigestAlgorithm digestAlgorithm) {
   final InputStream inputStream = openStream();
   final byte[] digestBytes = DSSUtils.digest(digestAlgorithm, inputStream);
   IOUtils.closeQuietly(inputStream);
   final String base64Encode = Base64.encodeBase64String(digestBytes);
   return base64Encode;
 }
Ejemplo n.º 4
0
 @Override
 public void save(final String filePath) {
   try {
     final FileOutputStream fos = new FileOutputStream(filePath);
     DSSUtils.write(getBytes(), fos);
     fos.close();
   } catch (DSSException e) {
     throw new DSSException(e);
   } catch (IOException e) {
     throw new DSSException(e);
   }
 }
Ejemplo n.º 5
0
  /**
   * This method returns the {@code ASN1Sequence} encapsulated in {@code DEROctetString}. The {@code
   * DEROctetString} is represented as {@code byte} array.
   *
   * @param bytes {@code byte} representation of {@code DEROctetString}
   * @return encapsulated {@code ASN1Sequence}
   * @throws DSSException in case of a decoding problem
   */
  public static ASN1Sequence getAsn1SequenceFromDerOctetString(byte[] bytes) throws DSSException {

    ASN1InputStream input = null;
    try {

      input = new ASN1InputStream(bytes);
      final DEROctetString s = (DEROctetString) input.readObject();
      final byte[] content = s.getOctets();
      input.close();
      input = new ASN1InputStream(content);
      final ASN1Sequence seq = (ASN1Sequence) input.readObject();
      return seq;
    } catch (IOException e) {
      throw new DSSException("Error when converting byte array to ASN1Sequence!", e);
    } finally {
      DSSUtils.closeQuietly(input);
    }
  }
Ejemplo n.º 6
0
  /**
   * This method generates a bouncycastle {@code TimeStampToken} based on base 64 encoded {@code
   * String}.
   *
   * @param base64EncodedTimestamp
   * @return bouncycastle {@code TimeStampToken}
   * @throws DSSException
   */
  public static TimeStampToken createTimeStampToken(final String base64EncodedTimestamp)
      throws DSSException {

    try {

      final byte[] tokenBytes = DSSUtils.base64Decode(base64EncodedTimestamp);
      final CMSSignedData signedData = new CMSSignedData(tokenBytes);
      return new TimeStampToken(signedData);
    } catch (DSSException e) {
      throw new DSSException(e);
    } catch (CMSException e) {
      throw new DSSException(e);
    } catch (TSPException e) {
      throw new DSSException(e);
    } catch (IOException e) {
      throw new DSSException(e);
    }
  }
Ejemplo n.º 7
0
 /**
  * Creates dss document that retains the data in memory
  *
  * @param inputStream input stream representing the document
  * @param name the file name if the data originates from a file
  * @param mimeType the mime type of the file if the data originates from a file
  * @throws IOException
  */
 public InMemoryDocument(final InputStream inputStream, final String name, final MimeType mimeType)
     throws DSSException {
   this(DSSUtils.toByteArray(inputStream), name, mimeType);
 }
Ejemplo n.º 8
0
 /**
  * Creates dss document that retains the data in memory
  *
  * @param inputStream input stream representing the document
  * @throws DSSException
  */
 public InMemoryDocument(final InputStream inputStream) throws DSSException {
   this(DSSUtils.toByteArray(inputStream), null, null);
 }
Ejemplo n.º 9
0
 @Override
 public String getDigest(final DigestAlgorithm digestAlgorithm) {
   final byte[] digestBytes = DSSUtils.digest(digestAlgorithm, bytes);
   final String base64Encode = Base64.encodeBase64String(digestBytes);
   return base64Encode;
 }
Ejemplo n.º 10
0
 @Override
 public void save(final String path) throws IOException {
   final InputStream inputStream = openStream();
   DSSUtils.saveToFile(inputStream, path);
   IOUtils.closeQuietly(inputStream);
 }
Ejemplo n.º 11
0
 @Override
 public InputStream openStream() throws DSSException {
   final InputStream inputStream = DSSUtils.toInputStream(file);
   return inputStream;
 }