当前位置: 首页>>代码示例>>Java>>正文


Java ASN1Primitive类代码示例

本文整理汇总了Java中org.spongycastle.asn1.ASN1Primitive的典型用法代码示例。如果您正苦于以下问题:Java ASN1Primitive类的具体用法?Java ASN1Primitive怎么用?Java ASN1Primitive使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ASN1Primitive类属于org.spongycastle.asn1包,在下文中一共展示了ASN1Primitive类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildPublicKey

import org.spongycastle.asn1.ASN1Primitive; //导入依赖的package包/类
static PublicKey buildPublicKey(byte[] rawBytes) throws CryptoException {
    try {
        //FIXME replacing X509EncodedKeySpec because of problem with 8.1
        //Since 8.1 Bouncycastle cryptography was replaced with implementation from Conscrypt
        //https://developer.android.com/about/versions/oreo/android-8.1.html
        //either it's a bug in Conscrypt, our public key DER structure or use of X509EncodedKeySpec changed
        //alternative needed as this adds expensive Spongycastle dependence
        ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(rawBytes));
        SubjectPublicKeyInfo info = SubjectPublicKeyInfo
                .getInstance(new ASN1InputStream(bIn.readObject().getEncoded()).readObject());
        DLSequence dlSequence = (DLSequence) ASN1Primitive.fromByteArray(info.getPublicKeyData().getBytes());
        BigInteger modulus = ((ASN1Integer) dlSequence.getObjectAt(0)).getPositiveValue();
        BigInteger exponent = ((ASN1Integer) dlSequence.getObjectAt(1)).getPositiveValue();

        RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent);
        KeyFactory kf = getRSAKeyFactory();
        return kf.generatePublic(spec);
    } catch (InvalidKeySpecException | IOException e) {
        throw new CryptoException(e);
    }
}
 
开发者ID:particle-iot,项目名称:spark-setup-android,代码行数:22,代码来源:Crypto.java

示例2: sign

import org.spongycastle.asn1.ASN1Primitive; //导入依赖的package包/类
@Override
public byte[] sign(InputStream content) throws IOException 
{
  CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
  SignatureData input = new SignatureData(content);
  List<Certificate> certs = new ArrayList<Certificate>();
  for (int i = 0; i < chain.length; i ++) {
    certs.add(chain[i]);
  }

  try
  {
    Store certStore = new JcaCertStore(certs);

    Certificate cert = chain[0];
    org.spongycastle.asn1.x509.Certificate x509Cert =
      org.spongycastle.asn1.x509.Certificate.getInstance(ASN1Primitive.fromByteArray(cert.getEncoded()));

    ContentSigner sha256Signer = new JcaContentSignerBuilder("SHA256withRSA").build(privKey);
    gen.addSignerInfoGenerator(
             new JcaSignerInfoGeneratorBuilder(
             new JcaDigestCalculatorProviderBuilder().build())
             .build(sha256Signer, new X509CertificateHolder(x509Cert)));

    gen.addCertificates(certStore);
    CMSSignedData signedData = gen.generate(input, false);
    return signedData.getEncoded();
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }
  throw new RuntimeException("Signing error, look at the stack trace");
}
 
开发者ID:KodeKreatif,项目名称:pdfdigisign,代码行数:35,代码来源:Signature.java

示例3: toASN1Primitive

import org.spongycastle.asn1.ASN1Primitive; //导入依赖的package包/类
@Override
public ASN1Primitive toASN1Primitive() {
    return keyData;
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:5,代码来源:SubjectPGPPublicKeyInfo.java


注:本文中的org.spongycastle.asn1.ASN1Primitive类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。