• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DERSequenceGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: toASN1

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
/**
 * Output this ECKey as an ASN.1 encoded private key, as understood by
 * OpenSSL or used by Bitcoin Core in its wallet storage format.
 * 
 * @throws eu.bittrade.crypto.core.ECKey.MissingPrivateKeyException
 *             if the private key is missing or encrypted.
 */
public byte[] toASN1() {
    try {
        byte[] privKeyBytes = getPrivKeyBytes();
        ByteArrayOutputStream baos = new ByteArrayOutputStream(400);

        // ASN1_SEQUENCE(EC_PRIVATEKEY) = {
        // ASN1_SIMPLE(EC_PRIVATEKEY, version, LONG),
        // ASN1_SIMPLE(EC_PRIVATEKEY, privateKey, ASN1_OCTET_STRING),
        // ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0),
        // ASN1_EXP_OPT(EC_PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1)
        // } ASN1_SEQUENCE_END(EC_PRIVATEKEY)
        DERSequenceGenerator seq = new DERSequenceGenerator(baos);
        seq.addObject(new ASN1Integer(1)); // version
        seq.addObject(new DEROctetString(privKeyBytes));
        seq.addObject(new DERTaggedObject(0, CURVE_PARAMS.toASN1Primitive()));
        seq.addObject(new DERTaggedObject(1, new DERBitString(getPubKey())));
        seq.close();
        return baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e); // Cannot happen, writing to memory
                                       // stream.
    }
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:31,代码来源:ECKey.java


示例2: toASN1

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
/**
 * Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the
 * BitCoin reference
 * implementation in its wallet storage format.
 */
public byte[] toASN1() {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(400);
        DERSequenceGenerator seq = new DERSequenceGenerator(baos);
        seq.addObject(new ASN1Integer(1)); // version
        seq.addObject(new DEROctetString(priv.toByteArray()));
        seq.addObject(new DERTaggedObject(0, SECNamedCurves.getByName("secp256k1")
                .toASN1Primitive()));
        seq.addObject(new DERTaggedObject(1, new DERBitString(getPubKey())));
        seq.close();
        return baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);  // Cannot happen, writing to memory stream.
    }
}
 
开发者ID:chaincloud-dot-com,项目名称:chaincloud-v,代码行数:21,代码来源:ECKey.java


示例3: toASN1

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
/**
 * Output this ECKey as an ASN.1 encoded private key, as understood by OpenSSL or used by the BitCoin reference
 * implementation in its wallet storage format.
 */
public byte[] toASN1() {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(400);

        // ASN1_SEQUENCE(EC_PRIVATEKEY) = {
        //   ASN1_SIMPLE(EC_PRIVATEKEY, version, LONG),
        //   ASN1_SIMPLE(EC_PRIVATEKEY, privateKey, ASN1_OCTET_STRING),
        //   ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0),
        //   ASN1_EXP_OPT(EC_PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1)
        // } ASN1_SEQUENCE_END(EC_PRIVATEKEY)
        DERSequenceGenerator seq = new DERSequenceGenerator(baos);
        seq.addObject(new ASN1Integer(1)); // version
        seq.addObject(new DEROctetString(priv.toByteArray()));
        seq.addObject(new DERTaggedObject(0, SECNamedCurves.getByName("secp256k1").toASN1Primitive()));
        seq.addObject(new DERTaggedObject(1, new DERBitString(getPubKey())));
        seq.close();
        return baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);  // Cannot happen, writing to memory stream.
    }
}
 
开发者ID:bither,项目名称:bitherj,代码行数:26,代码来源:ECKey.java


示例4: derByteStream

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
protected ByteArrayOutputStream derByteStream() throws IOException {
    // Usually 70-72 bytes.
    ByteArrayOutputStream bos = new ByteArrayOutputStream(72);
    DERSequenceGenerator seq = new DERSequenceGenerator(bos);
    seq.addObject(new ASN1Integer(r));
    seq.addObject(new ASN1Integer(s));
    seq.close();
    return bos;
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:10,代码来源:ECKey.java


示例5: getEncoded

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
/**
 	 * DER - From Big Integer rs to byte[]
 	 * UAF_ALG_SIGN_SECP256K1_ECDSA_SHA256_DER 0x06
 	 * DER [ITU-X690-2008] encoded ECDSA signature [RFC5480] on the secp256k1 curve.
 	 * I.e. a DER encoded SEQUENCE { r INTEGER, s INTEGER }
 	 * @param signature
 	 * @return
 	 * @throws IOException
 	 */
 	public static byte[] getEncoded(BigInteger[] sigs)
		throws IOException {
	ByteArrayOutputStream bos = new ByteArrayOutputStream(72);
	DERSequenceGenerator seq = new DERSequenceGenerator(bos);
	seq.addObject(new ASN1Integer(sigs[0]));
	seq.addObject(new ASN1Integer(sigs[1]));
	seq.close();
	return bos.toByteArray();
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:19,代码来源:Asn1.java


示例6: derByteStream

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
protected ByteArrayOutputStream derByteStream() throws IOException {
    // Usually 70-ic_launcher bytes.
    ByteArrayOutputStream bos = new ByteArrayOutputStream(72);
    DERSequenceGenerator seq = new DERSequenceGenerator(bos);
    seq.addObject(new ASN1Integer(r));
    seq.addObject(new ASN1Integer(s));
    seq.close();
    return bos;
}
 
开发者ID:chaincloud-dot-com,项目名称:chaincloud-v,代码行数:10,代码来源:ECKey.java


示例7: signTransaction

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
public boolean signTransaction(BigInteger privateKey) {
  ECPrivateKeyParameters privateKeyParams = new ECPrivateKeyParameters(privateKey, EC_PARAMS);
  ECDSASigner signer = new ECDSASigner();
  signer.init(true, privateKeyParams);
  byte[] hashedTransaction = Bitcoin.hash256(getBytes());
  BigInteger[] rawSignature = signer.generateSignature(hashedTransaction);
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(72);
    DERSequenceGenerator derGen = new DERSequenceGenerator(baos);
    derGen.addObject(new ASN1Integer(rawSignature[0]));
    derGen.addObject(new ASN1Integer(rawSignature[1]));
    derGen.close();
    byte[] ecdsaSignature = baos.toByteArray();
    byte[] publicKey = Bitcoin.generatePublicKey(privateKey);
    String signature = Bitcoin.encodeBase58(ecdsaSignature) + " " + Bitcoin.encodeBase58(publicKey);
    for (int i = 0; i < creations.size(); i++) {
      creations.get(i).setSignature(signature);
    }
    for (int i = 0; i < inputs.size(); i++) {
      inputs.get(i).setSignature(signature);
    }
    return true;
  } catch (IOException e) {
    e.printStackTrace();
    return false;
  }
}
 
开发者ID:Habitats,项目名称:bitcoupon,代码行数:28,代码来源:Transaction.java


示例8: signTransaction

import org.spongycastle.asn1.DERSequenceGenerator; //导入依赖的package包/类
public boolean signTransaction(BigInteger privateKey) {
  ECPrivateKeyParameters privateKeyParams = new ECPrivateKeyParameters(privateKey, Bitcoin.EC_PARAMS);
  ECDSASigner signer = new ECDSASigner();
  signer.init(true, privateKeyParams);
  byte[] hashedTransaction = Bitcoin.hash256(getBytes());
  BigInteger[] rawSignature = signer.generateSignature(hashedTransaction);
  try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(72);
    DERSequenceGenerator derGen = new DERSequenceGenerator(baos);
    derGen.addObject(new ASN1Integer(rawSignature[0]));
    derGen.addObject(new ASN1Integer(rawSignature[1]));
    derGen.close();
    byte[] ecdsaSignature = baos.toByteArray();
    byte[] publicKey = Bitcoin.generatePublicKey(privateKey);
    String signature = Bitcoin.encodeBase58(ecdsaSignature) + " " + Bitcoin.encodeBase58(publicKey);
    for (Creation creation : creations) {
      creation.setSignature(signature);
    }
    for (Input input : inputs) {
      input.setSignature(signature);
    }
    return true;
  } catch (IOException e) {
    e.printStackTrace();
    return false;
  }
}
 
开发者ID:bitcoupon,项目名称:bitcoupon-bitcoin-library,代码行数:28,代码来源:Transaction.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Datagram类代码示例发布时间:2022-05-23
下一篇:
Java INEIGuiHandler类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap