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

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

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

ASN1Primitive.getEncoded介绍

暂无

代码示例

代码示例来源:origin: square/okhttp

private ByteString pkcs1Bytes() {
 try {
  PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(keyPair.getPrivate().getEncoded());
  return ByteString.of(privateKeyInfo.parsePrivateKey().toASN1Primitive().getEncoded());
 } catch (IOException e) {
  throw new AssertionError(e);
 }
}

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

private static byte[] toByteArray(ASN1Primitive obj)
{
  try
  {
    return obj.getEncoded();
  }
  catch (IOException e)
  {
    throw new IllegalArgumentException("Unable to encode object");
  }
}

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

private static byte[] toByteArray(ASN1Primitive obj)
{
  try
  {
    return obj.getEncoded();
  }
  catch (IOException e)
  {
    throw new IllegalArgumentException("Unable to encode object");
  }
}

代码示例来源:origin: org.apache.camel/camel-asn1

@SuppressWarnings("rawtypes")
private Object createGenericTypeObject(ASN1Primitive current, Class<T> clazz2) throws Throwable {
  Class<?>[] paramIS = new Class[1];
  paramIS[0] = InputStream.class;
  Method m = clazz.getDeclaredMethod("decode", paramIS);
  InputStream is = new ByteArrayInputStream(current.getEncoded());
  Object clazzInstance = clazz.newInstance();
  m.invoke(clazzInstance, is);
  return clazzInstance;
}

代码示例来源:origin: stackoverflow.com

PublicKey pub = pair.getPublic();
byte[] pubBytes = pub.getEncoded();

SubjectPublicKeyInfo spkInfo = SubjectPublicKeyInfo.getInstance(pubBytes);
ASN1Primitive primitive = spkInfo.parsePublicKey();
byte[] publicKeyPKCS1 = primitive.getEncoded();

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

/**
 * Constructor from the encoding of an ASN.1 object.
 *
 * @param obj the object to be encoded.
 */
public DEROctetString(
  ASN1Encodable obj)
  throws IOException
{
  super(obj.toASN1Primitive().getEncoded(ASN1Encoding.DER));
}

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

public DERBitString(
  ASN1Encodable obj)
  throws IOException
{
  this.data = obj.toASN1Primitive().getEncoded(ASN1Encoding.DER);
  this.padBits = 0;
}

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

private byte[] getDEREncoded(
  ASN1Encodable obj)
{
  try
  {
    return obj.toASN1Primitive().getEncoded(ASN1Encoding.DER);
  }
  catch (IOException e)
  {
    throw new IllegalArgumentException("cannot encode object added to SET");
  }
}

代码示例来源:origin: stackoverflow.com

X509Certificate certificate = ...
byte[] encExtensionSubjectKeyIdentifier = certificate.getExtensionValue(Extension.subjectKeyIdentifier.getId());

// Unwrap first 'layer'
ASN1Primitive skiPrimitive = JcaX509ExtensionUtils.parseExtensionValue(encExtensionSubjectKeyIdentifier);

// Unwrap second 'layer'
byte[] keyIdentifier = ASN1OctetString.getInstance(skiPrimitive.getEncoded()).getOctets();

// Use keyIdentifier in e.g. CMS SignerInfo
SignerInfoGenerator signerInfoGenerator = jcaSignerInfoGeneratorBuilder.build(sha1Signer, keyIdentifier);

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

public DEROctetString(
  ASN1Encodable obj)
  throws IOException
{
  super(obj.toASN1Primitive().getEncoded(ASN1Encoding.DER));
}

代码示例来源:origin: stackoverflow.com

PrivateKey priv = pair.getPrivate();
byte[] privBytes = priv.getEncoded();

PrivateKeyInfo pkInfo = PrivateKeyInfo.getInstance(privBytes);
ASN1Encodable encodable = pkInfo.parsePrivateKey();
ASN1Primitive primitive = encodable.toASN1Primitive();
byte[] privateKeyPKCS1 = primitive.getEncoded();

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

public PrivateKeyInfo(
  AlgorithmIdentifier algId,
  ASN1Encodable       privateKey,
  ASN1Set             attributes)
  throws IOException
{
  this.privKey = new DEROctetString(privateKey.toASN1Primitive().getEncoded(ASN1Encoding.DER));
  this.algId = algId;
  this.attributes = attributes;
}

代码示例来源:origin: com.squareup.okhttp3/okhttp-tls

private ByteString pkcs1Bytes() {
 try {
  PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(keyPair.getPrivate().getEncoded());
  return ByteString.of(privateKeyInfo.parsePrivateKey().toASN1Primitive().getEncoded());
 } catch (IOException e) {
  throw new AssertionError(e);
 }
}

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

@SneakyThrows
public static String convertPublicKeyFromX509ToPkcs1Pem(final byte[] publicKeyX509) {
 // Convert public key from X.509 SubjectPublicKeyInfo to PKCS1:
 final ASN1Primitive publicKeyPrimitive = SubjectPublicKeyInfo.getInstance(publicKeyX509).parsePublicKey();
 return pem(publicKeyPrimitive.getEncoded(), RsaKey.KEY_FORMAT_PKCS1, RsaKey.KEY_TYPE_PUBLIC);
}

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

@SneakyThrows
public static String convertPrivateKeyFromPkcs8ToPkcs1Pem(final byte[] privateKeyPkcs8) {
 // Convert private key from PKCS8 to PKCS1:
 final ASN1Encodable encodable = PrivateKeyInfo.getInstance(privateKeyPkcs8).parsePrivateKey();
 return pem(encodable.toASN1Primitive().getEncoded(), RsaKey.KEY_FORMAT_PKCS1, RsaKey.KEY_TYPE_PRIVATE);
}

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

public DLBitString(
  ASN1Encodable obj)
  throws IOException
{
  super(obj.toASN1Primitive().getEncoded(ASN1Encoding.DER), 0);
}

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

private void verifySig(ASN1Encodable store, SignatureCheck integrityCheck, PublicKey key)
  throws GeneralSecurityException, IOException
{
  Signature sig = helper.createSignature(integrityCheck.getSignatureAlgorithm().getAlgorithm().getId());
  sig.initVerify(key);
  sig.update(store.toASN1Primitive().getEncoded(ASN1Encoding.DER));
  if (!sig.verify(integrityCheck.getSignature().getOctets()))
  {
    throw new IOException("BCFKS KeyStore corrupted: signature calculation failed");
  }
}

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

public DERBitString(
  ASN1Encodable obj)
  throws IOException
{
  super(obj.toASN1Primitive().getEncoded(ASN1Encoding.DER), 0);
}

代码示例来源:origin: org.cryptacular/cryptacular

@Override
 protected AsymmetricKeyParameter decodeASN1(final byte[] encoded)
 {
  try {
   return PrivateKeyFactory.createKey(new ASN1InputStream(encoded).readObject().getEncoded());
  } catch (IOException e) {
   throw new EncodingException("ASN.1 decoding error", e);
  }
 }
}

代码示例来源:origin: itext/itext7

private PdfName getSignatureHashKey(String signatureName) throws NoSuchAlgorithmException, IOException {
  PdfSignature sig = sgnUtil.getSignature(signatureName);
  PdfString contents = sig.getContents();
  byte[] bc = PdfEncodings.convertToBytes(contents.getValue(), null);
  byte[] bt = null;
  if (PdfName.ETSI_RFC3161.equals(sig.getSubFilter())) {
    ASN1InputStream din = new ASN1InputStream(new ByteArrayInputStream(bc));
    ASN1Primitive pkcs = din.readObject();
    bc = pkcs.getEncoded();
  }
  bt = hashBytesSha1(bc);
  return new PdfName(convertToHex(bt));
}

相关文章