eu.europa.esig.dss.utils.Utils.toBase64()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中eu.europa.esig.dss.utils.Utils.toBase64()方法的一些代码示例,展示了Utils.toBase64()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.toBase64()方法的具体详情如下:
包路径:eu.europa.esig.dss.utils.Utils
类名称:Utils
方法名:toBase64

Utils.toBase64介绍

暂无

代码示例

代码示例来源:origin: esig/dss

public String getBase64Encoded() {
  return Utils.toBase64(bytes);
}

代码示例来源:origin: esig/dss

@Override
public String getDigest(final DigestAlgorithm digestAlgorithm) {
  String base64EncodeDigest = base64EncodeDigestMap.get(digestAlgorithm);
  if (base64EncodeDigest == null) {
    final byte[] digestBytes = DSSUtils.digest(digestAlgorithm, this);
    base64EncodeDigest = Utils.toBase64(digestBytes);
    base64EncodeDigestMap.put(digestAlgorithm, base64EncodeDigest);
  }
  return base64EncodeDigest;
}

代码示例来源:origin: esig/dss

void addEquivalentCertificate(CertificateToken token) {
  if (!equivalentCertificates.contains(token)) {
    LOG.trace("Certificate with same public key detected : {}", token.getAbbreviation());
    // we manually recompute the SKI (we had cases with wrongly encoded value in the
    // certificate)
    final byte[] newSKI = DSSASN1Utils.computeSkiFromCert(token);
    CertificateToken equivalent = equivalentCertificates.iterator().next();
    final byte[] skiEquivalent = DSSASN1Utils.computeSkiFromCert(equivalent);
    // This should never happen
    if (!Arrays.equals(newSKI, skiEquivalent) && LOG.isWarnEnabled()) {
      LOG.warn("{} \nCERT : {} \nSKI : {} \nPubKey : {}", token, Utils.toBase64(token.getEncoded()), Utils.toBase64(newSKI),
          Utils.toBase64(token.getPublicKey().getEncoded()));
      LOG.warn("is not equivalent to");
      LOG.warn("{} \nCERT : {} \nSKI : {} \nPubKey : {}", equivalent, Utils.toBase64(equivalent.getEncoded()), Utils.toBase64(skiEquivalent),
          Utils.toBase64(token.getPublicKey().getEncoded()));
    } else {
      equivalentCertificates.add(token);
    }
  }
}

代码示例来源:origin: esig/dss

protected void addCRLBinary(byte[] binaries) {
  String base64Digest = Utils.toBase64(DSSUtils.digest(DigestAlgorithm.SHA256, binaries));
  addCRLBinary(base64Digest, binaries);
}

代码示例来源:origin: esig/dss

LOG.debug("Base64 content : {}", Utils.toBase64(bytes));

代码示例来源:origin: esig/dss

@Test
public void toBase64() {
  assertEquals("", Utils.toBase64(new byte[] {}));
  assertEquals("AQIDBAU=", Utils.toBase64(new byte[] { 1, 2, 3, 4, 5 }));
}

代码示例来源:origin: esig/dss

LOG.warn("Unable to parse the qCStatements extension '" + Utils.toBase64(qcStatement) + "' : " + e.getMessage(), e);

代码示例来源:origin: esig/dss

/**
 * Get the list of all QCStatement Ids that are present in the certificate.
 * (As per ETSI EN 319 412-5 V2.1.1)
 * 
 * @param certToken
 *            the certificate
 * @return the list of QC Statements oids
 */
public static List<String> getQCStatementsIdList(final CertificateToken certToken) {
  final List<String> extensionIdList = new ArrayList<String>();
  final byte[] qcStatement = certToken.getCertificate().getExtensionValue(Extension.qCStatements.getId());
  if (Utils.isArrayNotEmpty(qcStatement)) {
    try {
      final ASN1Sequence seq = getAsn1SequenceFromDerOctetString(qcStatement);
      // Sequence of QCStatement
      for (int ii = 0; ii < seq.size(); ii++) {
        final QCStatement statement = QCStatement.getInstance(seq.getObjectAt(ii));
        extensionIdList.add(statement.getStatementId().getId());
      }
    } catch (Exception e) {
      LOG.warn("Unable to parse the qCStatements extension '" + Utils.toBase64(qcStatement) + "' : " + e.getMessage(), e);
    }
  }
  return extensionIdList;
}

代码示例来源:origin: esig/dss

@Test
public void getDigest() throws IOException, GeneralSecurityException {
  try (InputStream is = CRLDigesterTest.class.getResourceAsStream("/belgium2.crl"); DigestInputStream dis = new DigestInputStream(is, getSHA1Digest())) {
    parser.processDigest(dis);
    byte[] digest = dis.getMessageDigest().digest();
    String computedBase64 = Utils.toBase64(digest);
    String expectedBase64Digest = "9G6GVRFhXI2bEXfhM98aXOsamXk=";
    assertEquals(computedBase64, expectedBase64Digest);
  }
}

代码示例来源:origin: esig/dss

@Test
public void loadCertificate() throws Exception {
  CertificateToken certificate = DSSUtils.loadCertificate(new FileInputStream("src/test/resources/belgiumrs2.crt"));
  assertNotNull(certificate);
  FileInputStream fis = new FileInputStream("src/test/resources/belgiumrs2.crt");
  byte[] byteArray = Utils.toByteArray(fis);
  logger.info(Utils.toBase64(byteArray));
  Utils.closeQuietly(fis);
  CertificateToken certificate2 = DSSUtils.loadCertificate(byteArray);
  assertNotNull(certificate2);
  CertificateToken certificateNew = DSSUtils.loadCertificate(new FileInputStream("src/test/resources/belgiumrs2-new.crt"));
  assertNotNull(certificateNew);
  FileInputStream fisNew = new FileInputStream("src/test/resources/belgiumrs2-new.crt");
  byte[] byteArrayNew = Utils.toByteArray(fisNew);
  logger.info(Utils.toBase64(byteArrayNew));
  Utils.closeQuietly(fisNew);
  CertificateToken certificate2New = DSSUtils.loadCertificate(byteArrayNew);
  assertNotNull(certificate2New);
  // String cert =
  // "PGh0bWw+PGhlYWQ+PHRpdGxlPlJlcXVlc3QgUmVqZWN0ZWQ8L3RpdGxlPjwvaGVhZD48Ym9keT5UaGUgcmVxdWVzdGVkIFVSTCB3YXMgcmVqZWN0ZWQuIFBsZWFzZSBjb25zdWx0IHdpdGggeW91ciBhZG1pbmlzdHJhdG9yLjxicj48YnI+WW91ciBzdXBwb3J0IElEIGlzOiAxMTY1Njg3NjQzMzgzMDI3NjMxNjwvYm9keT48L2h0bWw+";
  // byte[] decodeBase64 = Base64.decodeBase64(cert);
  // byte[] decodeBase642 = Base64.decodeBase64(decodeBase64);
  // CertificateToken certificate3 =
  // DSSUtils.loadCertificate(base64StringToBase64Binary);
  // assertNotNull(certificate3);
}

代码示例来源:origin: esig/dss

public static List<CertificatePolicy> getCertificatePolicies(final CertificateToken certToken) {
  List<CertificatePolicy> certificatePolicies = new ArrayList<CertificatePolicy>();
  final byte[] certificatePoliciesBinaries = certToken.getCertificate().getExtensionValue(Extension.certificatePolicies.getId());
  if (Utils.isArrayNotEmpty(certificatePoliciesBinaries)) {
    try {
      ASN1Sequence seq = getAsn1SequenceFromDerOctetString(certificatePoliciesBinaries);
      for (int ii = 0; ii < seq.size(); ii++) {
        CertificatePolicy cp = new CertificatePolicy();
        final PolicyInformation policyInfo = PolicyInformation.getInstance(seq.getObjectAt(ii));
        cp.setOid(policyInfo.getPolicyIdentifier().getId());
        ASN1Sequence policyQualifiersSeq = policyInfo.getPolicyQualifiers();
        if (policyQualifiersSeq != null) {
          for (int jj = 0; jj < policyQualifiersSeq.size(); jj++) {
            PolicyQualifierInfo pqi = PolicyQualifierInfo.getInstance(policyQualifiersSeq.getObjectAt(jj));
            if (PolicyQualifierId.id_qt_cps.equals(pqi.getPolicyQualifierId())) {
              cp.setCpsUrl(getString(pqi.getQualifier()));
            }
          }
        }
        certificatePolicies.add(cp);
      }
    } catch (Exception e) {
      LOG.warn("Unable to parse the certificatePolicies extension '" + Utils.toBase64(certificatePoliciesBinaries) + "' : " + e.getMessage(), e);
    }
  }
  return certificatePolicies;
}

相关文章