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


Java DERSequenceGenerator.addObject方法代码示例

本文整理汇总了Java中org.bouncycastle.asn1.DERSequenceGenerator.addObject方法的典型用法代码示例。如果您正苦于以下问题:Java DERSequenceGenerator.addObject方法的具体用法?Java DERSequenceGenerator.addObject怎么用?Java DERSequenceGenerator.addObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.asn1.DERSequenceGenerator的用法示例。


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

示例1: sign

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
@Override
public byte[] sign(byte[] hash, byte[] privateKey) {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    signer.init(true, new ECPrivateKeyParameters(new BigInteger(privateKey), domain));
    BigInteger[] signature = signer.generateSignature(hash);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        DERSequenceGenerator seq = new DERSequenceGenerator(baos);
        seq.addObject(new ASN1Integer(signature[0]));
        seq.addObject(new ASN1Integer(toCanonicalS(signature[1])));
        seq.close();
        return baos.toByteArray();
    } catch (IOException e) {
        return new byte[0];
    }
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:17,代码来源:BouncyCastleCrypto.java

示例2: encodeToDER

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
/**
 * Encodes R and S as a DER-encoded byte stream
 *
 * @return                          DER-encoded byte stream
 */
public byte[] encodeToDER() {
    byte[] encodedBytes = null;
    try {
        try (ByteArrayOutputStream outStream = new ByteArrayOutputStream(80)) {
            DERSequenceGenerator seq = new DERSequenceGenerator(outStream);
            seq.addObject(new ASN1Integer(r));
            seq.addObject(new ASN1Integer(s));
            seq.close();
            encodedBytes = outStream.toByteArray();
        }
    } catch (IOException exc) {
        throw new IllegalStateException("Unexpected IOException", exc);
    }
    return encodedBytes;
}
 
开发者ID:ScripterRon,项目名称:BitcoinCore,代码行数:21,代码来源:ECDSASignature.java

示例3: sign

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
@Override
public byte[] sign (byte[] hash) throws ValidationException
{
	if ( priv == null )
	{
		throw new ValidationException ("Need private key to sign");
	}
	ECDSASigner signer = new ECDSASigner (new HMacDSAKCalculator (new SHA256Digest ()));
	signer.init (true, new ECPrivateKeyParameters (priv, domain));
	BigInteger[] signature = signer.generateSignature (hash);
	ByteArrayOutputStream s = new ByteArrayOutputStream ();
	try
	{
		DERSequenceGenerator seq = new DERSequenceGenerator (s);
		seq.addObject (new ASN1Integer (signature[0]));
		seq.addObject (new ASN1Integer (signature[1]));
		seq.close ();
		return s.toByteArray ();
	}
	catch ( IOException e )
	{
	}
	return null;
}
 
开发者ID:bitsofproof,项目名称:bop-bitcoin-client,代码行数:25,代码来源:ECKeyPair.java

示例4: open

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
/**
 * @deprecated use open(OutputStream, ASN1ObjectIdentifier, ContentCompressor)
 */
public OutputStream open(
    OutputStream  out,        
    String        contentOID,
    String        compressionOID) 
    throws IOException
{
    BERSequenceGenerator sGen = new BERSequenceGenerator(out);
    
    sGen.addObject(CMSObjectIdentifiers.compressedData);
    
    //
    // Compressed Data
    //
    BERSequenceGenerator cGen = new BERSequenceGenerator(sGen.getRawOutputStream(), 0, true);
    
    cGen.addObject(new ASN1Integer(0));
    
    //
    // AlgorithmIdentifier
    //
    DERSequenceGenerator algGen = new DERSequenceGenerator(cGen.getRawOutputStream());
    
    algGen.addObject(new ASN1ObjectIdentifier(ZLIB));

    algGen.close();
    
    //
    // Encapsulated ContentInfo
    //
    BERSequenceGenerator eiGen = new BERSequenceGenerator(cGen.getRawOutputStream());
    
    eiGen.addObject(new ASN1ObjectIdentifier(contentOID));

    OutputStream octetStream = CMSUtils.createBEROctetOutputStream(
        eiGen.getRawOutputStream(), 0, true, _bufferSize);
    
    return new CmsCompressedOutputStream(
        new DeflaterOutputStream(octetStream), sGen, cGen, eiGen);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:43,代码来源:CMSCompressedDataStreamGenerator.java

示例5: sign

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
/**
 * Sign a digest with this key.
 *
 * @param hash arbitrary data
 * @return signature
 */
public byte[] sign(byte[] hash) {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    signer.init(true, new ECPrivateKeyParameters(priv, domain));
    BigInteger[] signature = signer.generateSignature(hash);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        DERSequenceGenerator seq = new DERSequenceGenerator(baos);
        seq.addObject(new ASN1Integer(signature[0]));
        seq.addObject(new ASN1Integer(toCanonicalS(signature[1])));
        seq.close();
        return baos.toByteArray();
    } catch (IOException e) {
    }
    return null;
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:22,代码来源:PrivateKey.java

示例6: ecdsaSignToBytes

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
/**
 * Sign data with the specified elliptic curve private key.
 *
 * @param privateKey elliptic curve private key.
 * @param data       data to sign
 * @return the signed data.
 * @throws CryptoException
 */
private byte[] ecdsaSignToBytes(ECPrivateKey privateKey, byte[] data) throws CryptoException {
    try {
        X9ECParameters params = ECNamedCurveTable.getByName(curveName);
        BigInteger curveN = params.getN();

        Signature sig = SECURITY_PROVIDER == null ? Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM) :
                                                    Signature.getInstance(DEFAULT_SIGNATURE_ALGORITHM, SECURITY_PROVIDER);
        sig.initSign(privateKey);
        sig.update(data);
        byte[] signature = sig.sign();

        BigInteger[] sigs = decodeECDSASignature(signature);

        sigs = preventMalleability(sigs, curveN);

        ByteArrayOutputStream s = new ByteArrayOutputStream();

        DERSequenceGenerator seq = new DERSequenceGenerator(s);
        seq.addObject(new ASN1Integer(sigs[0]));
        seq.addObject(new ASN1Integer(sigs[1]));
        seq.close();
        return s.toByteArray();

    } catch (Exception e) {
        throw new CryptoException("Could not sign the message using private key", e);
    }

}
 
开发者ID:hyperledger,项目名称:fabric-sdk-java,代码行数:37,代码来源:CryptoPrimitives.java

示例7: calculateBlockHash

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
/**
 * used asn1 and get hash
 *
 * @param blockNumber
 * @param previousHash
 * @param dataHash
 * @return byte[]
 * @throws IOException
 * @throws InvalidArgumentException
 */
public static byte[] calculateBlockHash(HFClient client, long blockNumber, byte[] previousHash, byte[] dataHash) throws IOException, InvalidArgumentException {

    if (previousHash == null) {
        throw new InvalidArgumentException("previousHash parameter is null.");
    }
    if (dataHash == null) {
        throw new InvalidArgumentException("dataHash parameter is null.");
    }
    if (null == client) {
        throw new InvalidArgumentException("client parameter is null.");
    }

    CryptoSuite cryptoSuite = client.getCryptoSuite();
    if (null == client) {
        throw new InvalidArgumentException("Client crypto suite has not  been set.");
    }

    ByteArrayOutputStream s = new ByteArrayOutputStream();
    DERSequenceGenerator seq = new DERSequenceGenerator(s);
    seq.addObject(new ASN1Integer(blockNumber));
    seq.addObject(new DEROctetString(previousHash));
    seq.addObject(new DEROctetString(dataHash));
    seq.close();
    return cryptoSuite.hash(s.toByteArray());

}
 
开发者ID:hyperledger,项目名称:fabric-sdk-java,代码行数:37,代码来源:SDKUtils.java

示例8: sign

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
public byte[] sign(byte[] message) throws Exception
{
    if (priv == null) {
        throw new Exception("Unable to sign");
    }
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    signer.init(true, new ECPrivateKeyParameters(priv, params));
    BigInteger[] signature = signer.generateSignature(message);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DERSequenceGenerator seqGen = new DERSequenceGenerator(outputStream);
    seqGen.addObject(new ASN1Integer(signature[0]));
    seqGen.addObject(new ASN1Integer(signature[1]));
    seqGen.close();
    return outputStream.toByteArray();
}
 
开发者ID:bushidowallet,项目名称:bushido-java-core,代码行数:16,代码来源:ECKey.java

示例9: signData

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
static String signData(String input, byte[] key) throws BlockIOException {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    X9ECParameters params = SECNamedCurves.getByName("secp256k1");
    ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
    BigInteger priv = new BigInteger(1, key);
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, ecParams);

    signer.init(true, privKey);
    BigInteger[] sigs = signer.generateSignature(fromHex(input));

    BigInteger r = sigs[0];
    BigInteger s = sigs[1];

    // BIP62: "S must be less than or equal to half of the Group Order N"
    BigInteger overTwo = params.getN().shiftRight(1);
    if (s.compareTo(overTwo) == 1) {
        s = params.getN().subtract(s);
    }

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DERSequenceGenerator seq = new DERSequenceGenerator(bos);
        seq.addObject(new ASN1Integer(r));
        seq.addObject(new ASN1Integer(s));
        seq.close();
        return toHex(bos.toByteArray());
    } catch (IOException e) {
        throw new BlockIOException("That should never happen... File an issue report.");  // Cannot happen.
    }
}
 
开发者ID:langerhans,项目名称:blockio-java,代码行数:31,代码来源:SigningUtils.java

示例10: testDERWriting

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
public void testDERWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   DERSequenceGenerator  seqGen = new DERSequenceGenerator(bOut);
   
   seqGen.addObject(new DERInteger(BigInteger.valueOf(0)));
   
   seqGen.addObject(new DERObjectIdentifier("1.1"));
   
   seqGen.close();

   assertTrue("basic DER writing test failed.", Arrays.equals(seqData, bOut.toByteArray()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:15,代码来源:ASN1SequenceParserTest.java

示例11: testDERExplicitTaggedSequenceWriting

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
public void testDERExplicitTaggedSequenceWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   DERSequenceGenerator  seqGen = new DERSequenceGenerator(bOut, 1, true);
   
   seqGen.addObject(new DERInteger(BigInteger.valueOf(0)));
   
   seqGen.addObject(new DERObjectIdentifier("1.1"));
   
   seqGen.close();

   assertTrue("explicit tag writing test failed.", Arrays.equals(expTagSeqData, bOut.toByteArray()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:15,代码来源:ASN1SequenceParserTest.java

示例12: testDERImplicitTaggedSequenceWriting

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
public void testDERImplicitTaggedSequenceWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   DERSequenceGenerator  seqGen = new DERSequenceGenerator(bOut, 1, false);
   
   seqGen.addObject(new DERInteger(BigInteger.valueOf(0)));
   
   seqGen.addObject(new DERObjectIdentifier("1.1"));
   
   seqGen.close();

   assertTrue("implicit tag writing test failed.", Arrays.equals(implTagSeqData, bOut.toByteArray()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:15,代码来源:ASN1SequenceParserTest.java

示例13: encodeToDER

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
/**
 * What we get back from the signer are the two components of a signature, r and s. To get a flat byte stream
 * of the type used by Bitcoin we have to encode them using DER encoding, which is just a way to pack the two
 * components into a structure.
 */
public byte[] encodeToDER() {
    try {
        // Usually 70-72 bytes.
        ByteArrayOutputStream bos = new ByteArrayOutputStream(72);
        DERSequenceGenerator seq = new DERSequenceGenerator(bos);
        seq.addObject(new DERInteger(r));
        seq.addObject(new DERInteger(s));
        seq.close();
        return bos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);  // Cannot happen.
    }
}
 
开发者ID:pmarches,项目名称:jStellarAPI,代码行数:19,代码来源:StellarSigner.java

示例14: testNestedDERWriting

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
public void testNestedDERWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   DERSequenceGenerator seqGen1 = new DERSequenceGenerator(bOut);
   
   seqGen1.addObject(new DERInteger(BigInteger.valueOf(0)));
   
   seqGen1.addObject(new DERObjectIdentifier("1.1"));
   
   DERSequenceGenerator seqGen2 = new DERSequenceGenerator(seqGen1.getRawOutputStream());
   
   seqGen2.addObject(new DERInteger(BigInteger.valueOf(1)));
   
   seqGen2.close();
   
   seqGen1.close();

   assertTrue("nested DER writing test failed.", Arrays.equals(nestedSeqData, bOut.toByteArray()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:21,代码来源:ASN1SequenceParserTest.java

示例15: testNestedExplicitTagDERWriting

import org.bouncycastle.asn1.DERSequenceGenerator; //导入方法依赖的package包/类
public void testNestedExplicitTagDERWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   DERSequenceGenerator  seqGen1 = new DERSequenceGenerator(bOut);
   
   seqGen1.addObject(new DERInteger(BigInteger.valueOf(0)));
   
   seqGen1.addObject(new DERObjectIdentifier("1.1"));
   
   DERSequenceGenerator seqGen2 = new DERSequenceGenerator(seqGen1.getRawOutputStream(), 1, true);
   
   seqGen2.addObject(new DERInteger(BigInteger.valueOf(1)));
   
   seqGen2.close();
   
   seqGen1.close();

   assertTrue("nested explicit tagged DER writing test failed.", Arrays.equals(nestedSeqExpTagData, bOut.toByteArray()));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:21,代码来源:ASN1SequenceParserTest.java


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