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


Java BigIntegers.asUnsignedByteArray方法代码示例

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


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

示例1: getSM2Z

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public static byte[] getSM2Z(byte[] userID, ASN1ObjectIdentifier curveOid,
        BigInteger pubPointX, BigInteger pubPointY) {
    SM3Digest digest = new SM3Digest();

    addUserID(digest, userID);

    X9ECParameters ecParams = GMNamedCurves.getByOID(curveOid);
    addFieldElement(digest, ecParams.getCurve().getA());
    addFieldElement(digest, ecParams.getCurve().getB());
    addFieldElement(digest, ecParams.getG().getAffineXCoord());
    addFieldElement(digest, ecParams.getG().getAffineYCoord());

    int fieldSize = (ecParams.getCurve().getFieldSize() + 7) / 8;
    byte[] bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointX);
    digest.update(bytes, 0, fieldSize);

    bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointY);
    digest.update(bytes, 0, fieldSize);

    byte[] result = new byte[digest.getDigestSize()];
    digest.doFinal(result, 0);
    return result;
}
 
开发者ID:xipki,项目名称:xitk,代码行数:24,代码来源:GMUtil.java

示例2: ECPrivateKeyStructure

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public ECPrivateKeyStructure(
    BigInteger    key,
    DERBitString  publicKey,
    ASN1Encodable parameters)
{
    byte[] bytes = BigIntegers.asUnsignedByteArray(key);

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(1));
    v.add(new DEROctetString(bytes));

    if (parameters != null)
    {
        v.add(new DERTaggedObject(true, 0, parameters));
    }

    if (publicKey != null)
    {
        v.add(new DERTaggedObject(true, 1, publicKey));
    }

    seq = new DERSequence(v);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:ECPrivateKeyStructure.java

示例3: ECPrivateKey

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public ECPrivateKey(
    int orderBitLength,
    BigInteger key,
    DERBitString publicKey,
    ASN1Encodable parameters)
{
    byte[] bytes = BigIntegers.asUnsignedByteArray((orderBitLength + 7) / 8, key);

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(1));
    v.add(new DEROctetString(bytes));

    if (parameters != null)
    {
        v.add(new DERTaggedObject(true, 0, parameters));
    }

    if (publicKey != null)
    {
        v.add(new DERTaggedObject(true, 1, publicKey));
    }

    seq = new DERSequence(v);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:26,代码来源:ECPrivateKey.java

示例4: isFinalSolutionCorrect

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
@Override
public boolean isFinalSolutionCorrect(BigInteger guessedSecret) {
    // BigInteger correct = new
    // BigInteger("25091756309879652045519159642875354611257005804552159157");
    // if (correct.compareTo(guessedSecret) == 0) {
    // return true;
    // } else {
    // return false;
    // }

    computer.setSecret(guessedSecret);
    try {
        Point p = computer.mul(checkPoint);
        byte[] pms = BigIntegers.asUnsignedByteArray(curve.getKeyBits() / 8, p.getX());
        return Arrays.equals(checkPMS, pms);
    } catch (DivisionException ex) {
        LOGGER.debug(ex);
        return false;
    }
}
 
开发者ID:RUB-NDS,项目名称:TLS-Attacker,代码行数:21,代码来源:RealDirectMessageECOracle.java

示例5: encrypt

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
/**
 * Generate and encapsulate a random session key.
 *
 * @param out    the output buffer for the encapsulated key.
 * @param outOff the offset for the output buffer.
 * @param keyLen the length of the random session key.
 * @return the random session key.
 */
public CipherParameters encrypt(byte[] out, int outOff, int keyLen)
    throws IllegalArgumentException
{
    if (key.isPrivate())
    {
        throw new IllegalArgumentException("Public key required for encryption");
    }

    BigInteger n = key.getModulus();
    BigInteger e = key.getExponent();

    // Generate the ephemeral random and encode it    
    BigInteger r = BigIntegers.createRandomInRange(ZERO, n.subtract(ONE), rnd);

    // Encrypt the random and encode it     
    BigInteger c = r.modPow(e, n);
    byte[] C = BigIntegers.asUnsignedByteArray((n.bitLength() + 7) / 8, c);
    System.arraycopy(C, 0, out, outOff, C.length);

    return generateKey(n, r, keyLen);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:30,代码来源:RSAKeyEncapsulation.java

示例6: generatePremasterSecret

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public byte[] generatePremasterSecret() throws IOException
{
    try
    {
        BigInteger S = srpServer != null
            ?   srpServer.calculateSecret(srpPeerCredentials)
            :   srpClient.calculateSecret(srpPeerCredentials);

        // TODO Check if this needs to be a fixed size
        return BigIntegers.asUnsignedByteArray(S);
    }
    catch (CryptoException e)
    {
        throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:17,代码来源:TlsSRPKeyExchange.java

示例7: generateSignature

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
/**
 * generate a signature for the loaded message using the key we were
 * initialised with.
 */
public byte[] generateSignature()
    throws CryptoException
{
    createSignatureBlock();

    BigInteger t = new BigInteger(1, cipher.processBlock(block, 0, block.length));
    BigInteger nSubT = kParam.getModulus().subtract(t);

    clearBlock(block);

    BigInteger v = kParam.getModulus().shiftRight(2);

    if (t.compareTo(nSubT) > 0)
    {
        return BigIntegers.asUnsignedByteArray((kParam.getModulus().bitLength() + 7) / 8, nSubT);
    }
    else
    {
        return BigIntegers.asUnsignedByteArray((kParam.getModulus().bitLength() + 7) / 8, t);
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:26,代码来源:X931Signer.java

示例8: calculateDHBasicAgreement

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public static byte[] calculateDHBasicAgreement(DHPublicKeyParameters publicKey,
                                               DHPrivateKeyParameters privateKey)
{

    DHBasicAgreement basicAgreement = new DHBasicAgreement();
    basicAgreement.init(privateKey);
    BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);

    /*
     * RFC 5246 8.1.2. Leading bytes of Z that contain all zero bits are stripped before it is
     * used as the pre_master_secret.
     */
    return BigIntegers.asUnsignedByteArray(agreementValue);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:TlsDHUtils.java

示例9: generateEphemeralClientKeyExchange

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public static DHPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random,
                                                                        DHParameters dhParams, OutputStream output)
    throws IOException
{

    AsymmetricCipherKeyPair dhAgreeClientKeyPair = generateDHKeyPair(random, dhParams);
    DHPrivateKeyParameters dhAgreeClientPrivateKey = (DHPrivateKeyParameters)dhAgreeClientKeyPair
        .getPrivate();

    BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.getPublic()).getY();
    byte[] keData = BigIntegers.asUnsignedByteArray(Yc);
    TlsUtils.writeOpaque16(keData, output);

    return dhAgreeClientPrivateKey;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:TlsDHUtils.java

示例10: calculateECDHBasicAgreement

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey)
{

    ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement();
    basicAgreement.init(privateKey);
    BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);

    /*
     * RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by
     * FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for
     * any given field; leading zeros found in this octet string MUST NOT be truncated.
     */
    return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:TlsECCUtils.java

示例11: generateAgreement

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public byte[] generateAgreement(AsymmetricKeyParameter peerPublicKey)
{
    basicAgreement.init(privateKey);
    BigInteger agreementValue = basicAgreement.calculateAgreement(peerPublicKey);

    if (truncateAgreement)
    {
        return BigIntegers.asUnsignedByteArray(agreementValue);
    }

    return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:DefaultTlsAgreementCredentials.java

示例12: generateClientKeyExchange

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public void generateClientKeyExchange(OutputStream output)
    throws IOException
{
    byte[] keData = BigIntegers.asUnsignedByteArray(srpClient.generateClientCredentials(s, this.identity,
        this.password));
    TlsUtils.writeOpaque16(keData, output);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:TlsSRPKeyExchange.java

示例13: generatePremasterSecret

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public byte[] generatePremasterSecret()
    throws IOException
{
    try
    {
        // TODO Check if this needs to be a fixed size
        return BigIntegers.asUnsignedByteArray(srpClient.calculateSecret(B));
    }
    catch (CryptoException e)
    {
        throw new TlsFatalAlert(AlertDescription.illegal_parameter);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:TlsSRPKeyExchange.java

示例14: setNonce

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
public void setNonce(BigInteger nonce)
{
    // RFC 3029, 9.1: The DVCS MAY modify the fields
    // 'dvcs', 'requester', 'dataLocations', and 'nonce' of the ReqInfo structure

    // RFC 3029, 9.1: The only modification
    // allowed to a 'nonce' is the inclusion of a new field if it was not
    // present, or to concatenate other data to the end (right) of an
    // existing value.
    if (initialInfo != null)
    {
        if (initialInfo.getNonce() == null)
        {
            this.nonce = nonce;
        }
        else
        {
            byte[] initialBytes = initialInfo.getNonce().toByteArray();
            byte[] newBytes = BigIntegers.asUnsignedByteArray(nonce);
            byte[] nonceBytes = new byte[initialBytes.length + newBytes.length];

            System.arraycopy(initialBytes, 0, nonceBytes, 0, initialBytes.length);
            System.arraycopy(newBytes, 0, nonceBytes, initialBytes.length, newBytes.length);

            this.nonce = new BigInteger(nonceBytes);
        }
    }

    this.nonce = nonce;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:31,代码来源:DVCSRequestInformationBuilder.java

示例15: getPadded

import org.bouncycastle.util.BigIntegers; //导入方法依赖的package包/类
private static byte[] getPadded(BigInteger n, int length)
{
    byte[] bs = BigIntegers.asUnsignedByteArray(n);
    if (bs.length < length)
    {
        byte[] tmp = new byte[length];
        System.arraycopy(bs, 0, tmp, length - bs.length, bs.length);
        bs = tmp;
    }
    return bs;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:12,代码来源:SRP6Util.java


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