org.bouncycastle.asn1.ASN1Sequence.fromByteArray()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(174)

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

ASN1Sequence.fromByteArray介绍

暂无

代码示例

代码示例来源:origin: cn.home1/oss-lib-common-spring-boot-1.4.2.RELEASE

@SneakyThrows
public static RSAPrivateKey privateKeyPkcs1(final String pkcs1) {
 final String withoutComment = dropComment(pkcs1, COMMENT_MARK);
 final byte[] raw = CodecUtils.decodeBase64(withoutComment);
 if (log.isDebugEnabled()) {
  log.debug("withoutComment: {}", withoutComment);
  log.debug("raw: {}", Hex.encodeHexString(raw));
 }
 final ASN1Primitive asn1Primitive = ASN1Sequence.fromByteArray(raw);
 // final RSAPrivateKeyStructure asn1 = new RSAPrivateKeyStructure((ASN1Sequence) asn1Primitive);
 final org.bouncycastle.asn1.pkcs.RSAPrivateKey asn1 =
  org.bouncycastle.asn1.pkcs.RSAPrivateKey.getInstance(asn1Primitive);
 final RSAPrivateKeySpec rsaPrivateKeySpec = new RSAPrivateKeySpec(asn1.getModulus(), asn1.getPrivateExponent());
 return (RSAPrivateKey) KeyFactory.getInstance(ALGO_RSA).generatePrivate(rsaPrivateKeySpec);
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

byte[] asn = Base64.getDecoder().decode(key);
ASN1Sequence primitive = (ASN1Sequence) ASN1Sequence.fromByteArray(asn);
Enumeration<?> ex = primitive.getObjects();
BigInteger v = ((ASN1Integer) ex.nextElement()).getValue();

代码示例来源:origin: open-eid/digidoc4j

/**
 * Returns current certificate policies or null if no policies was found.
 *
 * @return list of policies
 * @throws IOException when policy parsing fails
 */
public List<String> getCertificatePolicies() throws IOException {
 logger.debug("");
 byte[] extensionValue = originalCert.getExtensionValue("2.5.29.32");
 List<String> policies = new ArrayList<>();
 byte[] octets = ((DEROctetString) DEROctetString.fromByteArray(extensionValue)).getOctets();
 ASN1Sequence sequence = (ASN1Sequence) ASN1Sequence.fromByteArray(octets);
 Enumeration sequenceObjects = sequence.getObjects();
 while (sequenceObjects.hasMoreElements()) {
  DLSequence next = (DLSequence) sequenceObjects.nextElement();
  Object objectAt = next.getObjectAt(0);
  if (objectAt != null) {
   policies.add(objectAt.toString());
  }
 }
 return policies;
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

return ASN1Sequence.getInstance(fromByteArray((byte[])obj));

代码示例来源:origin: de.mhus.lib/mhu-lib-core

byte[] asn = Base64.getDecoder().decode(key);
ASN1Sequence primitive = (ASN1Sequence) ASN1Sequence.fromByteArray(asn);
Enumeration<?> ex = primitive.getObjects();
BigInteger v = ((ASN1Integer) ex.nextElement()).getValue();

代码示例来源:origin: redfish64/TinyTravelTracker

return ASN1Sequence.getInstance(fromByteArray((byte[])obj));

代码示例来源:origin: palantir/conjure-java-runtime

@Override
public RSAPrivateKeySpec readPrivateKey(byte[] privateKeyDerBytes) throws IOException {
  RSAPrivateKey asn1PrivKey = RSAPrivateKey.getInstance(ASN1Sequence.fromByteArray(privateKeyDerBytes));
  return new RSAPrivateKeySpec(asn1PrivKey.getModulus(), asn1PrivKey.getPrivateExponent());
}

代码示例来源:origin: xiangwbs/springboot

/**
 * 从字符串中加载私钥
 *
 * @param privateKeyStr
 * @return
 */
public static RSAPrivateKey loadPrivateKey(String privateKeyStr) {
  try {
    BASE64Decoder base64Decoder = new BASE64Decoder();
    byte[] priKeyData = base64Decoder.decodeBuffer(privateKeyStr);
    // 读pkcs#8码
    // PKCS8EncodedKeySpec keySpec= new PKCS8EncodedKeySpec(priKeyData);
    // 读pkcs#1码(传统私钥格式)
    RSAPrivateKeyStructure asn1PrivKey = new RSAPrivateKeyStructure(
        (ASN1Sequence) ASN1Sequence.fromByteArray(priKeyData));
    RSAPrivateKeySpec rsaPrivKeySpec = new RSAPrivateKeySpec(
        asn1PrivKey.getModulus(), asn1PrivKey.getPrivateExponent());
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    return (RSAPrivateKey) keyFactory.generatePrivate(rsaPrivKeySpec);
  } catch (NoSuchAlgorithmException e) {
    log.error(e.getMessage());
    throw new UtilException("无此算法");
  } catch (InvalidKeySpecException e) {
    log.error(e.getMessage());
    throw new UtilException("私钥非法");
  } catch (IOException e) {
    log.error(e.getMessage());
    throw new UtilException("私钥数据内容读取错误");
  }
}

代码示例来源:origin: org.codeartisans.qipki/qipki-crypto

@Override
@SuppressWarnings( "SetReplaceableByEnumSet" )
public Set<ExtendedKeyUsage> getExtendedKeyUsages( X509Certificate cert )
{
  try {
    byte[] value = cert.getExtensionValue( X509Extensions.ExtendedKeyUsage.getId() );
    if ( value == null ) {
      return Collections.emptySet();
    }
    byte[] asn1octets = ( ( ASN1OctetString ) ASN1Object.fromByteArray( value ) ).getOctets();
    org.bouncycastle.asn1.x509.ExtendedKeyUsage usages = org.bouncycastle.asn1.x509.ExtendedKeyUsage.getInstance( ( ASN1Sequence ) ASN1Sequence.fromByteArray( asn1octets ) );
    Set<ExtendedKeyUsage> keyUsages = new LinkedHashSet<ExtendedKeyUsage>();
    for ( ExtendedKeyUsage eachPossible : ExtendedKeyUsage.values() ) {
      if ( usages.hasKeyPurposeId( eachPossible.getKeyPurposeId() ) ) {
        keyUsages.add( eachPossible );
      }
    }
    return keyUsages;
  } catch ( IOException ex ) {
    throw new CryptoFailure( "Unable to extract ExtendedKeyUsages from X509Certificate extensions", ex );
  }
}

代码示例来源:origin: zero11it/acme-client

public static String getCACertificateURL(X509Certificate certificate) throws IOException {
    byte[] bOctets = ((ASN1OctetString) ASN1Primitive.fromByteArray(certificate.getExtensionValue(Extension.authorityInfoAccess.getId()))).getOctets();
    AuthorityInformationAccess access = AuthorityInformationAccess.getInstance(ASN1Sequence.fromByteArray(bOctets));
    for (AccessDescription ad:access.getAccessDescriptions()){
      if (ad.getAccessMethod().equals(X509ObjectIdentifiers.id_ad_caIssuers)){
        return ad.getAccessLocation().getName().toString();
      }
    }
    return null;
  }
}

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

ASN1Sequence sequenceExtensions = (ASN1Sequence) ASN1Sequence.fromByteArray(array);
extractExtensions(sequenceExtensions, infos);

代码示例来源:origin: edu.vt.middleware/vt-crypt

System.arraycopy(encoded, len + 2, privatePart, 0, privatePart.length);
try {
 final ASN1Sequence seq = (ASN1Sequence) ASN1Sequence.fromByteArray(
  privatePart);
 spec = new ECPrivateKeySpec(

相关文章