Java 类org.bouncycastle.asn1.cryptopro.GOST3410PublicKeyAlgParameters 实例源码

项目:ipack    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    PrivateKeyInfo info)
    throws IOException
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    ASN1OctetString      derX = ASN1OctetString.getInstance(info.parsePrivateKey());
    byte[]              keyEnc = derX.getOctets();
    byte[]              keyBytes = new byte[keyEnc.length];

    for (int i = 0; i != keyEnc.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
    }

    this.x = new BigInteger(1, keyBytes);
    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:Aki-SSL    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    PrivateKeyInfo info)
    throws IOException
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    ASN1OctetString      derX = ASN1OctetString.getInstance(info.parsePrivateKey());
    byte[]              keyEnc = derX.getOctets();
    byte[]              keyBytes = new byte[keyEnc.length];

    for (int i = 0; i != keyEnc.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
    }

    this.x = new BigInteger(1, keyBytes);
    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:CryptMeme    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    PrivateKeyInfo info)
    throws IOException
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    ASN1OctetString      derX = ASN1OctetString.getInstance(info.parsePrivateKey());
    byte[]              keyEnc = derX.getOctets();
    byte[]              keyBytes = new byte[keyEnc.length];

    for (int i = 0; i != keyEnc.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
    }

    this.x = new BigInteger(1, keyBytes);
    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:irma_future_id    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    PrivateKeyInfo info)
    throws IOException
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    ASN1OctetString      derX = ASN1OctetString.getInstance(info.parsePrivateKey());
    byte[]              keyEnc = derX.getOctets();
    byte[]              keyBytes = new byte[keyEnc.length];

    for (int i = 0; i != keyEnc.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
    }

    this.x = new BigInteger(1, keyBytes);
    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:bc-java    文件:BCGOST3410PrivateKey.java   
BCGOST3410PrivateKey(
    PrivateKeyInfo info)
    throws IOException
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    ASN1OctetString      derX = ASN1OctetString.getInstance(info.parsePrivateKey());
    byte[]              keyEnc = derX.getOctets();
    byte[]              keyBytes = new byte[keyEnc.length];

    for (int i = 0; i != keyEnc.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
    }

    this.x = new BigInteger(1, keyBytes);
    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:ipack    文件:GOST3410ParameterSpec.java   
public static GOST3410ParameterSpec fromPublicKeyAlg(
    GOST3410PublicKeyAlgParameters params)
{
    if (params.getEncryptionParamSet() != null)
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId(), params.getEncryptionParamSet().getId());
    }
    else
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId());
    }
}
项目:ipack    文件:AlgorithmParametersSpi.java   
/**
 * Return the X.509 ASN.1 structure GOST3410Parameter.
 * <p/>
 * <pre>
 *  GOST3410Parameter ::= SEQUENCE {
 *                   prime INTEGER, -- p
 *                   subprime INTEGER, -- q
 *                   base INTEGER, -- a}
 * </pre>
 */
protected byte[] engineGetEncoded()
{
    GOST3410PublicKeyAlgParameters gost3410P = new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(currentSpec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getDigestParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getEncryptionParamSetOID()));

    try
    {
        return gost3410P.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding GOST3410Parameters");
    }
}
项目:Aki-SSL    文件:GOST3410ParameterSpec.java   
public static GOST3410ParameterSpec fromPublicKeyAlg(
    GOST3410PublicKeyAlgParameters params)
{
    if (params.getEncryptionParamSet() != null)
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId(), params.getEncryptionParamSet().getId());
    }
    else
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId());
    }
}
项目:Aki-SSL    文件:AlgorithmParametersSpi.java   
/**
 * Return the X.509 ASN.1 structure GOST3410Parameter.
 * <pre>
 *  GOST3410Parameter ::= SEQUENCE {
 *                   prime INTEGER, -- p
 *                   subprime INTEGER, -- q
 *                   base INTEGER, -- a}
 * </pre>
 */
protected byte[] engineGetEncoded()
{
    GOST3410PublicKeyAlgParameters gost3410P = new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(currentSpec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getDigestParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getEncryptionParamSetOID()));

    try
    {
        return gost3410P.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding GOST3410Parameters");
    }
}
项目:Aki-SSL    文件:BCGOST3410PublicKey.java   
BCGOST3410PublicKey(
    SubjectPublicKeyInfo info)
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    DEROctetString                    derY;

    try
    {
        derY = (DEROctetString)info.parsePublicKey();

        byte[]                  keyEnc = derY.getOctets();
        byte[]                  keyBytes = new byte[keyEnc.length];

        for (int i = 0; i != keyEnc.length; i++)
        {
            keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
        }

        this.y = new BigInteger(1, keyBytes);
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("invalid info structure in GOST3410 public key");
    }

    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:CryptMeme    文件:GOST3410ParameterSpec.java   
public static GOST3410ParameterSpec fromPublicKeyAlg(
    GOST3410PublicKeyAlgParameters params)
{
    if (params.getEncryptionParamSet() != null)
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId(), params.getEncryptionParamSet().getId());
    }
    else
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId());
    }
}
项目:CryptMeme    文件:AlgorithmParametersSpi.java   
/**
 * Return the X.509 ASN.1 structure GOST3410Parameter.
 * <p/>
 * <pre>
 *  GOST3410Parameter ::= SEQUENCE {
 *                   prime INTEGER, -- p
 *                   subprime INTEGER, -- q
 *                   base INTEGER, -- a}
 * </pre>
 */
protected byte[] engineGetEncoded()
{
    GOST3410PublicKeyAlgParameters gost3410P = new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(currentSpec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getDigestParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getEncryptionParamSetOID()));

    try
    {
        return gost3410P.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding GOST3410Parameters");
    }
}
项目:CryptMeme    文件:BCGOST3410PublicKey.java   
BCGOST3410PublicKey(
    SubjectPublicKeyInfo info)
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    DEROctetString                    derY;

    try
    {
        derY = (DEROctetString)info.parsePublicKey();

        byte[]                  keyEnc = derY.getOctets();
        byte[]                  keyBytes = new byte[keyEnc.length];

        for (int i = 0; i != keyEnc.length; i++)
        {
            keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
        }

        this.y = new BigInteger(1, keyBytes);
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("invalid info structure in GOST3410 public key");
    }

    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:irma_future_id    文件:GOST3410ParameterSpec.java   
public static GOST3410ParameterSpec fromPublicKeyAlg(
    GOST3410PublicKeyAlgParameters params)
{
    if (params.getEncryptionParamSet() != null)
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId(), params.getEncryptionParamSet().getId());
    }
    else
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId());
    }
}
项目:irma_future_id    文件:AlgorithmParametersSpi.java   
/**
 * Return the X.509 ASN.1 structure GOST3410Parameter.
 * <p/>
 * <pre>
 *  GOST3410Parameter ::= SEQUENCE {
 *                   prime INTEGER, -- p
 *                   subprime INTEGER, -- q
 *                   base INTEGER, -- a}
 * </pre>
 */
protected byte[] engineGetEncoded()
{
    GOST3410PublicKeyAlgParameters gost3410P = new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(currentSpec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getDigestParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getEncryptionParamSetOID()));

    try
    {
        return gost3410P.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding GOST3410Parameters");
    }
}
项目:irma_future_id    文件:BCGOST3410PublicKey.java   
BCGOST3410PublicKey(
    SubjectPublicKeyInfo info)
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    DEROctetString                    derY;

    try
    {
        derY = (DEROctetString)info.parsePublicKey();

        byte[]                  keyEnc = derY.getOctets();
        byte[]                  keyBytes = new byte[keyEnc.length];

        for (int i = 0; i != keyEnc.length; i++)
        {
            keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
        }

        this.y = new BigInteger(1, keyBytes);
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("invalid info structure in GOST3410 public key");
    }

    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:bc-java    文件:GOST3410ParameterSpec.java   
public static GOST3410ParameterSpec fromPublicKeyAlg(
    GOST3410PublicKeyAlgParameters params)
{
    if (params.getEncryptionParamSet() != null)
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId(), params.getEncryptionParamSet().getId());
    }
    else
    {
        return new GOST3410ParameterSpec(params.getPublicKeyParamSet().getId(), params.getDigestParamSet().getId());
    }
}
项目:bc-java    文件:AlgorithmParametersSpi.java   
/**
 * Return the X.509 ASN.1 structure GOST3410Parameter.
 * <p/>
 * <pre>
 *  GOST3410Parameter ::= SEQUENCE {
 *                   prime INTEGER, -- p
 *                   subprime INTEGER, -- q
 *                   base INTEGER, -- a}
 * </pre>
 */
protected byte[] engineGetEncoded()
{
    GOST3410PublicKeyAlgParameters gost3410P = new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(currentSpec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getDigestParamSetOID()), new ASN1ObjectIdentifier(currentSpec.getEncryptionParamSetOID()));

    try
    {
        return gost3410P.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding GOST3410Parameters");
    }
}
项目:bc-java    文件:BCGOST3410PublicKey.java   
BCGOST3410PublicKey(
    SubjectPublicKeyInfo info)
{
    GOST3410PublicKeyAlgParameters    params = new GOST3410PublicKeyAlgParameters((ASN1Sequence)info.getAlgorithmId().getParameters());
    DEROctetString                    derY;

    try
    {
        derY = (DEROctetString)info.parsePublicKey();

        byte[]                  keyEnc = derY.getOctets();
        byte[]                  keyBytes = new byte[keyEnc.length];

        for (int i = 0; i != keyEnc.length; i++)
        {
            keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // was little endian
        }

        this.y = new BigInteger(1, keyBytes);
    }
    catch (IOException e)
    {
        throw new IllegalArgumentException("invalid info structure in GOST3410 public key");
    }

    this.gost3410Spec = GOST3410ParameterSpec.fromPublicKeyAlg(params);
}
项目:Aki-SSL    文件:BCGOST3410PublicKey.java   
public byte[] getEncoded()
{
    SubjectPublicKeyInfo    info;
    byte[]                  keyEnc = this.getY().toByteArray();
    byte[]                  keyBytes;

    if (keyEnc[0] == 0)
    {
        keyBytes = new byte[keyEnc.length - 1];
    }
    else
    {
        keyBytes = new byte[keyEnc.length];
    }

    for (int i = 0; i != keyBytes.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // must be little endian
    }

    try
    {
        if (gost3410Spec instanceof GOST3410ParameterSpec)
        {
            if (gost3410Spec.getEncryptionParamSetOID() != null)
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getEncryptionParamSetOID()))), new DEROctetString(keyBytes));
            }
            else
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()))), new DEROctetString(keyBytes));
            }
        }
        else
        {
            info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94), new DEROctetString(keyBytes));
        }

        return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:Aki-SSL    文件:BCECGOST3410PublicKey.java   
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
    DERBitString bits = info.getPublicKeyData();
    ASN1OctetString key;
    this.algorithm = "ECGOST3410";

    try
    {
        key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
    }
    catch (IOException ex)
    {
        throw new IllegalArgumentException("error recovering public key");
    }

    byte[] keyEnc = key.getOctets();
    byte[] x = new byte[32];
    byte[] y = new byte[32];

    for (int i = 0; i != x.length; i++)
    {
        x[i] = keyEnc[32 - 1 - i];
    }

    for (int i = 0; i != y.length; i++)
    {
        y[i] = keyEnc[64 - 1 - i];
    }

    gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());

    ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));

    ECCurve curve = spec.getCurve();
    EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());

    this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));

    ecSpec = new ECNamedCurveSpec(
        ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
        ellipticCurve,
        new ECPoint(
            spec.getG().getAffineXCoord().toBigInteger(),
            spec.getG().getAffineYCoord().toBigInteger()),
        spec.getN(), spec.getH());
}
项目:Aki-SSL    文件:BCECGOST3410PublicKey.java   
public GOST3410PublicKeyAlgParameters getGostParams()
{
    return gostParams;
}
项目:CryptMeme    文件:BCGOST3410PublicKey.java   
public byte[] getEncoded()
{
    SubjectPublicKeyInfo    info;
    byte[]                  keyEnc = this.getY().toByteArray();
    byte[]                  keyBytes;

    if (keyEnc[0] == 0)
    {
        keyBytes = new byte[keyEnc.length - 1];
    }
    else
    {
        keyBytes = new byte[keyEnc.length];
    }

    for (int i = 0; i != keyBytes.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // must be little endian
    }

    try
    {
        if (gost3410Spec instanceof GOST3410ParameterSpec)
        {
            if (gost3410Spec.getEncryptionParamSetOID() != null)
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getEncryptionParamSetOID()))), new DEROctetString(keyBytes));
            }
            else
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()))), new DEROctetString(keyBytes));
            }
        }
        else
        {
            info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94), new DEROctetString(keyBytes));
        }

        return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:CryptMeme    文件:BCECGOST3410PublicKey.java   
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
    DERBitString bits = info.getPublicKeyData();
    ASN1OctetString key;
    this.algorithm = "ECGOST3410";

    try
    {
        key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
    }
    catch (IOException ex)
    {
        throw new IllegalArgumentException("error recovering public key");
    }

    byte[] keyEnc = key.getOctets();
    byte[] x = new byte[32];
    byte[] y = new byte[32];

    for (int i = 0; i != x.length; i++)
    {
        x[i] = keyEnc[32 - 1 - i];
    }

    for (int i = 0; i != y.length; i++)
    {
        y[i] = keyEnc[64 - 1 - i];
    }

    gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());

    ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));

    ECCurve curve = spec.getCurve();
    EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());

    this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));

    ecSpec = new ECNamedCurveSpec(
        ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
        ellipticCurve,
        new ECPoint(
            spec.getG().getAffineXCoord().toBigInteger(),
            spec.getG().getAffineYCoord().toBigInteger()),
        spec.getN(), spec.getH());
}
项目:CryptMeme    文件:BCECGOST3410PublicKey.java   
public GOST3410PublicKeyAlgParameters getGostParams()
{
    return gostParams;
}
项目:irma_future_id    文件:BCGOST3410PublicKey.java   
public byte[] getEncoded()
{
    SubjectPublicKeyInfo    info;
    byte[]                  keyEnc = this.getY().toByteArray();
    byte[]                  keyBytes;

    if (keyEnc[0] == 0)
    {
        keyBytes = new byte[keyEnc.length - 1];
    }
    else
    {
        keyBytes = new byte[keyEnc.length];
    }

    for (int i = 0; i != keyBytes.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // must be little endian
    }

    try
    {
        if (gost3410Spec instanceof GOST3410ParameterSpec)
        {
            if (gost3410Spec.getEncryptionParamSetOID() != null)
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getEncryptionParamSetOID()))), new DEROctetString(keyBytes));
            }
            else
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()))), new DEROctetString(keyBytes));
            }
        }
        else
        {
            info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94), new DEROctetString(keyBytes));
        }

        return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:irma_future_id    文件:BCECGOST3410PublicKey.java   
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
    DERBitString bits = info.getPublicKeyData();
    ASN1OctetString key;
    this.algorithm = "ECGOST3410";

    try
    {
        key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
    }
    catch (IOException ex)
    {
        throw new IllegalArgumentException("error recovering public key");
    }

    byte[] keyEnc = key.getOctets();
    byte[] x = new byte[32];
    byte[] y = new byte[32];

    for (int i = 0; i != x.length; i++)
    {
        x[i] = keyEnc[32 - 1 - i];
    }

    for (int i = 0; i != y.length; i++)
    {
        y[i] = keyEnc[64 - 1 - i];
    }

    gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());

    ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));

    ECCurve curve = spec.getCurve();
    EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());

    this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));

    ecSpec = new ECNamedCurveSpec(
        ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
        ellipticCurve,
        new ECPoint(
            spec.getG().getX().toBigInteger(),
            spec.getG().getY().toBigInteger()),
        spec.getN(), spec.getH());
}
项目:irma_future_id    文件:BCECGOST3410PublicKey.java   
public GOST3410PublicKeyAlgParameters getGostParams()
{
    return gostParams;
}
项目:bc-java    文件:BCGOST3410PublicKey.java   
public byte[] getEncoded()
{
    SubjectPublicKeyInfo    info;
    byte[]                  keyEnc = this.getY().toByteArray();
    byte[]                  keyBytes;

    if (keyEnc[0] == 0)
    {
        keyBytes = new byte[keyEnc.length - 1];
    }
    else
    {
        keyBytes = new byte[keyEnc.length];
    }

    for (int i = 0; i != keyBytes.length; i++)
    {
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i]; // must be little endian
    }

    try
    {
        if (gost3410Spec instanceof GOST3410ParameterSpec)
        {
            if (gost3410Spec.getEncryptionParamSetOID() != null)
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getEncryptionParamSetOID()))), new DEROctetString(keyBytes));
            }
            else
            {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()))), new DEROctetString(keyBytes));
            }
        }
        else
        {
            info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94), new DEROctetString(keyBytes));
        }

        return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:bc-java    文件:BCECGOST3410PublicKey.java   
private void populateFromPubKeyInfo(SubjectPublicKeyInfo info)
{
    DERBitString bits = info.getPublicKeyData();
    ASN1OctetString key;
    this.algorithm = "ECGOST3410";

    try
    {
        key = (ASN1OctetString)ASN1Primitive.fromByteArray(bits.getBytes());
    }
    catch (IOException ex)
    {
        throw new IllegalArgumentException("error recovering public key");
    }

    byte[] keyEnc = key.getOctets();
    byte[] x = new byte[32];
    byte[] y = new byte[32];

    for (int i = 0; i != x.length; i++)
    {
        x[i] = keyEnc[32 - 1 - i];
    }

    for (int i = 0; i != y.length; i++)
    {
        y[i] = keyEnc[64 - 1 - i];
    }

    gostParams = GOST3410PublicKeyAlgParameters.getInstance(info.getAlgorithm().getParameters());

    ECNamedCurveParameterSpec spec = ECGOST3410NamedCurveTable.getParameterSpec(ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()));

    ECCurve curve = spec.getCurve();
    EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getSeed());

    this.q = curve.createPoint(new BigInteger(1, x), new BigInteger(1, y));

    ecSpec = new ECNamedCurveSpec(
        ECGOST3410NamedCurves.getName(gostParams.getPublicKeyParamSet()),
        ellipticCurve,
        new ECPoint(
            spec.getG().getX().toBigInteger(),
            spec.getG().getY().toBigInteger()),
        spec.getN(), spec.getH());
}
项目:bc-java    文件:BCECGOST3410PublicKey.java   
public GOST3410PublicKeyAlgParameters getGostParams()
{
    return gostParams;
}