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


Java DSAPrivateKey.getX方法代码示例

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


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

示例1: extractK

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
/** Extract the k that was used to sign the signature. Validates the k if check == true. */
BigInteger extractK(byte[] signature, BigInteger h, DSAPrivateKey priv, boolean check)
    throws Exception {
  BigInteger x = priv.getX();
  BigInteger q = priv.getParams().getQ();
  BigInteger r = extractR(signature);
  BigInteger s = extractS(signature);
  BigInteger k = x.multiply(r).add(h).multiply(s.modInverse(q)).mod(q);
  if (check) {
    BigInteger p = priv.getParams().getP();
    BigInteger g = priv.getParams().getG();
    BigInteger r2 = g.modPow(k, p).mod(q);
    assertEquals(r.toString(), r2.toString());
  }
  return k;
}
 
开发者ID:google,项目名称:wycheproof,代码行数:17,代码来源:DsaTest.java

示例2: regenerateLocalPublicKey

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
public void regenerateLocalPublicKey(KeyFactory factory, String fullUserId, DSAPrivateKey privKey) {

        String userId = Address.stripResource(fullUserId);

        BigInteger x = privKey.getX();
        DSAParams params = privKey.getParams();
        BigInteger y = params.getG().modPow(x, params.getP());
        DSAPublicKeySpec keySpec = new DSAPublicKeySpec(y, params.getP(), params.getQ(), params.getG());
        PublicKey pubKey;
        try {
            pubKey = factory.generatePublic(keySpec);
            storeLocalPublicKey(userId, pubKey);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
 
开发者ID:zom,项目名称:Zom-Android,代码行数:19,代码来源:OtrAndroidKeyManagerImpl.java

示例3: getPublicKey

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
public PublicKey getPublicKey() throws GeneralSecurityException {
    if (privateKey instanceof DSAPrivateKey) {
        DSAPrivateKey dsa = (DSAPrivateKey) privateKey;
        DSAParams params = dsa.getParams();
        BigInteger g = params.getG();
        BigInteger p = params.getP();
        BigInteger q = params.getQ();
        BigInteger x = dsa.getX();
        BigInteger y = q.modPow( x, p );
        DSAPublicKeySpec dsaKeySpec = new DSAPublicKeySpec(y, p, q, g);
        return KeyFactory.getInstance("DSA").generatePublic(dsaKeySpec);
    } else if (privateKey instanceof RSAPrivateCrtKey) {
        RSAPrivateCrtKey rsa = (RSAPrivateCrtKey) privateKey;
        RSAPublicKeySpec rsaKeySpec = new RSAPublicKeySpec(
                rsa.getModulus(),
                rsa.getPublicExponent()
        );
        return KeyFactory.getInstance("RSA").generatePublic(rsaKeySpec);
    } else {
        throw new GeneralSecurityException("Not an RSA or DSA key");
    }
}
 
开发者ID:drankye,项目名称:haox,代码行数:23,代码来源:PKCS8Key.java

示例4: regenerateLocalPublicKey

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
public void regenerateLocalPublicKey(KeyFactory factory, String fullUserId, DSAPrivateKey privKey) {
    
    String userId = Address.stripResource(fullUserId);

    
    BigInteger x = privKey.getX();
    DSAParams params = privKey.getParams();
    BigInteger y = params.getG().modPow(x, params.getP());
    DSAPublicKeySpec keySpec = new DSAPublicKeySpec(y, params.getP(), params.getQ(), params.getG());
    PublicKey pubKey;
    try {
        pubKey = factory.generatePublic(keySpec);
    } catch (InvalidKeySpecException e) {
        throw new RuntimeException(e);
    }
    storeLocalPublicKey(userId, pubKey);
}
 
开发者ID:prive,项目名称:prive-android,代码行数:18,代码来源:OtrAndroidKeyManagerImpl.java

示例5: generatePrivateKeyParameter

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof DSAPrivateKey)
    {
        DSAPrivateKey    k = (DSAPrivateKey)key;

        return new DSAPrivateKeyParameters(k.getX(),
            new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG()));
    }
                    
    throw new InvalidKeyException("can't identify DSA private key.");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:DSAUtil.java

示例6: generatePrivateKeyParameter

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof DSAPrivateKey)
    {
        DSAPrivateKey    k = (DSAPrivateKey)key;

        return new DSAPrivateKeyParameters(k.getX(),
            new DSAParameters(k.getParams().getP(), k.getParams().getQ(), k.getParams().getG()));
    }

    throw new InvalidKeyException("can't identify DSA private key.");
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:15,代码来源:DSAUtil.java

示例7: initSign

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void initSign() {
	if (signKey == null) {
		throw new IllegalStateException(
				"Sign key must be set prior to initialization.");
	}

	final DSAPrivateKey privKey = (DSAPrivateKey) signKey;
	final DSAParams params = privKey.getParams();
	final DSAPrivateKeyParameters bcParams = new DSAPrivateKeyParameters(
			privKey.getX(), new DSAParameters(params.getP(), params.getQ(),
					params.getG()));
	init(true, bcParams);
}
 
开发者ID:shivam091,项目名称:Java-Security,代码行数:15,代码来源:DSASignature.java

示例8: fromJavaKey

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
public static SigningPrivateKey fromJavaKey(DSAPrivateKey pk)
                          throws GeneralSecurityException {
    BigInteger x = pk.getX();
    SigType type = SigType.DSA_SHA1;
    int len = type.getPrivkeyLen();
    byte[] bx = rectify(x, len);
    return new SigningPrivateKey(type, bx);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:9,代码来源:SigUtil.java

示例9: engineInitSign

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
/** <b>SPI: </b> Initializes this object for signing
using the private key

@param key the private key
@exception InvalidKeyException if the key class doesn't
implement than DSAPrivateKey
   */
   protected void engineInitSign(PrivateKey key)
     throws InvalidKeyException {
     if(!(key instanceof DSAPrivateKey))
throw new InvalidKeyException(getAlgorithm() +
  ": Not a DSA Private Key");

     DSAPrivateKey dsa=(DSAPrivateKey)key;
     extractParams(dsa.getParams());
     XY=dsa.getX();
   }
 
开发者ID:NCIP,项目名称:cagrid2,代码行数:18,代码来源:RawDSASignature.java

示例10: JDKDSAPrivateKey

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
JDKDSAPrivateKey(
    DSAPrivateKey    key)
{
    this.x = key.getX();
    this.dsaSpec = key.getParams();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:7,代码来源:JDKDSAPrivateKey.java

示例11: BCDSAPrivateKey

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
BCDSAPrivateKey(
    DSAPrivateKey key)
{
    this.x = key.getX();
    this.dsaSpec = key.getParams();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:7,代码来源:BCDSAPrivateKey.java

示例12: get

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
/**
 * OpenSSL encode a private key.
 *
 * @return The encoding
 * @param privateKey
 *            The private key
 * @throws CryptoException
 *             Problem encountered while getting the encoded private key
 */
public static byte[] get(PrivateKey privateKey) throws CryptoException {
	// DER encoding for each key type is a sequence
	ASN1EncodableVector vec = new ASN1EncodableVector();

	if (privateKey instanceof ECPrivateKey) {
		try {
			ECPrivateKey ecPrivKey = (ECPrivateKey) privateKey;
			org.bouncycastle.asn1.sec.ECPrivateKey keyStructure = EccUtil.convertToECPrivateKeyStructure(ecPrivKey);
			return keyStructure.toASN1Primitive().getEncoded();
		} catch (IOException e) {
			throw new CryptoException(res.getString("NoDerEncodeOpenSslPrivateKey.exception.message"), e);
		}
	} else if (privateKey instanceof RSAPrivateCrtKey) {
		RSAPrivateCrtKey rsaPrivateKey = (RSAPrivateCrtKey) privateKey;

		vec.add(new ASN1Integer(VERSION));
		vec.add(new ASN1Integer(rsaPrivateKey.getModulus()));
		vec.add(new ASN1Integer(rsaPrivateKey.getPublicExponent()));
		vec.add(new ASN1Integer(rsaPrivateKey.getPrivateExponent()));
		vec.add(new ASN1Integer(rsaPrivateKey.getPrimeP()));
		vec.add(new ASN1Integer(rsaPrivateKey.getPrimeQ()));
		vec.add(new ASN1Integer(rsaPrivateKey.getPrimeExponentP()));
		vec.add(new ASN1Integer(rsaPrivateKey.getPrimeExponentQ()));
		vec.add(new ASN1Integer(rsaPrivateKey.getCrtCoefficient()));
	} else {
		DSAPrivateKey dsaPrivateKey = (DSAPrivateKey) privateKey;
		DSAParams dsaParams = dsaPrivateKey.getParams();

		BigInteger primeModulusP = dsaParams.getP();
		BigInteger primeQ = dsaParams.getQ();
		BigInteger generatorG = dsaParams.getG();
		BigInteger secretExponentX = dsaPrivateKey.getX();

		// Derive public key from private key parts, ie Y = G^X mod P
		BigInteger publicExponentY = generatorG.modPow(secretExponentX, primeModulusP);

		vec.add(new ASN1Integer(VERSION));
		vec.add(new ASN1Integer(primeModulusP));
		vec.add(new ASN1Integer(primeQ));
		vec.add(new ASN1Integer(generatorG));
		vec.add(new ASN1Integer(publicExponentY));
		vec.add(new ASN1Integer(secretExponentX));
	}
	DERSequence derSequence = new DERSequence(vec);

	try {
		return derSequence.getEncoded();
	} catch (IOException ex) {
		throw new CryptoException(res.getString("NoDerEncodeOpenSslPrivateKey.exception.message"), ex);
	}
}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:61,代码来源:OpenSslPvkUtil.java

示例13: sign

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
public byte[] sign(byte[] b, PrivateKey privatekey) throws OtrCryptoException {

        if (!(privatekey instanceof DSAPrivateKey))
            throw new IllegalArgumentException();

        DSAParams dsaParams = ((DSAPrivateKey) privatekey).getParams();
        DSAParameters bcDSAParameters = new DSAParameters(dsaParams.getP(), dsaParams.getQ(),
                dsaParams.getG());

        DSAPrivateKey dsaPrivateKey = (DSAPrivateKey) privatekey;
        DSAPrivateKeyParameters bcDSAPrivateKeyParms = new DSAPrivateKeyParameters(
                dsaPrivateKey.getX(), bcDSAParameters);

        DSASigner dsaSigner = new DSASigner();
        dsaSigner.init(true, bcDSAPrivateKeyParms);

        BigInteger q = dsaParams.getQ();

        // Ian: Note that if you can get the standard DSA implementation you're
        // using to not hash its input, you should be able to pass it ((256-bit
        // value) mod q), (rather than truncating the 256-bit value) and all
        // should be well.
        // ref: Interop problems with libotr - DSA signature
        BigInteger bmpi = new BigInteger(1, b);
        BigInteger[] rs = dsaSigner.generateSignature(BigIntegers.asUnsignedByteArray(bmpi.mod(q)));

        int siglen = q.bitLength() / 4;
        int rslen = siglen / 2;
        byte[] rb = BigIntegers.asUnsignedByteArray(rs[0]);
        byte[] sb = BigIntegers.asUnsignedByteArray(rs[1]);

        // Create the final signature array, padded with zeros if necessary.
        byte[] sig = new byte[siglen];
        Boolean writeR = false;
        Boolean writeS = false;
        int shiftR = rslen - rb.length;
        int shiftS = rslen - sb.length;

        for (int i = 0; i < siglen; i++) {
            if (i < rslen) {
                if (!writeR)
                    writeR = rb.length >= rslen - i;
                sig[i] = (writeR) ? rb[i - shiftR] : (byte) 0x0;
            } else {
                int j = i - rslen; // Rebase.
                if (!writeS)
                    writeS = sb.length >= rslen - j;
                sig[i] = (writeS) ? sb[j - shiftS] : (byte) 0x0;
            }
        }
        return sig;
    }
 
开发者ID:zom,项目名称:Zom-Android,代码行数:53,代码来源:OtrCryptoEngineImpl.java

示例14: sign

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
public byte[] sign(byte[] b, PrivateKey privatekey) throws OtrCryptoException {

        if (!(privatekey instanceof DSAPrivateKey))
            throw new IllegalArgumentException();

        DSAParams dsaParams = ((DSAPrivateKey) privatekey).getParams();
        DSAParameters bcDSAParameters = new DSAParameters(dsaParams.getP(), dsaParams.getQ(),
                dsaParams.getG());

        DSAPrivateKey dsaPrivateKey = (DSAPrivateKey) privatekey;
        DSAPrivateKeyParameters bcDSAPrivateKeyParms = new DSAPrivateKeyParameters(
                dsaPrivateKey.getX(), bcDSAParameters);

        DSASigner dsaSigner = new DSASigner();
        dsaSigner.init(true, bcDSAPrivateKeyParms);

        BigInteger q = dsaParams.getQ();

        // Ian: Note that if you can get the standard DSA implementation you're
        // using to not hash its input, you should be able to pass it ((256-bit
        // value) mod q), (rather than truncating the 256-bit value) and all
        // should be well.
        // ref: Interop problems with libotr - DSA signature
        BigInteger bmpi = new BigInteger(1, b);
        BigInteger[] rs = dsaSigner.generateSignature(BigIntegers.asUnsignedByteArray(bmpi.mod(q)));

        int siglen = q.bitLength() / 4;
        int rslen = siglen / 2;
        byte[] rb = BigIntegers.asUnsignedByteArray(rs[0]);
        byte[] sb = BigIntegers.asUnsignedByteArray(rs[1]);

        // Create the final signature array, padded with zeros if necessary.
        byte[] sig = new byte[siglen];
        Boolean writeR = false;
        Boolean writeS = false;
        int shiftR = rslen - rb.length;
        int shiftS = rslen - sb.length;
        
        for (int i = 0; i < siglen; i++) {
            if (i < rslen) {
                if (!writeR)
                    writeR = rb.length >= rslen - i;
                sig[i] = (writeR) ? rb[i - shiftR] : (byte) 0x0;
            } else {
                int j = i - rslen; // Rebase.
                if (!writeS)
                    writeS = sb.length >= rslen - j;
                sig[i] = (writeS) ? sb[j - shiftS] : (byte) 0x0;
            }
        }
        return sig;
    }
 
开发者ID:prive,项目名称:prive-android,代码行数:53,代码来源:OtrCryptoEngineImpl.java

示例15: sign

import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
public byte[] sign(byte[] b, PrivateKey privatekey)
		throws OtrCryptoException {

	if (!(privatekey instanceof DSAPrivateKey))
		throw new IllegalArgumentException();

	DSAParams dsaParams = ((DSAPrivateKey) privatekey).getParams();
	DSAParameters bcDSAParameters = new DSAParameters(dsaParams.getP(),
			dsaParams.getQ(), dsaParams.getG());

	DSAPrivateKey dsaPrivateKey = (DSAPrivateKey) privatekey;
	DSAPrivateKeyParameters bcDSAPrivateKeyParms = new DSAPrivateKeyParameters(
			dsaPrivateKey.getX(), bcDSAParameters);

	DSASigner dsaSigner = new DSASigner();
	dsaSigner.init(true, bcDSAPrivateKeyParms);

	BigInteger q = dsaParams.getQ();

	// Ian: Note that if you can get the standard DSA implementation you're
	// using to not hash its input, you should be able to pass it ((256-bit
	// value) mod q), (rather than truncating the 256-bit value) and all
	// should be well.
	// ref: Interop problems with libotr - DSA signature
	BigInteger bmpi = new BigInteger(1, b);
	BigInteger[] rs = dsaSigner.generateSignature(BigIntegers
			.asUnsignedByteArray(bmpi.mod(q)));

	int siglen = q.bitLength() / 4;
	int rslen = siglen / 2;
	byte[] rb = BigIntegers.asUnsignedByteArray(rs[0]);
	byte[] sb = BigIntegers.asUnsignedByteArray(rs[1]);

	// Create the final signature array, padded with zeros if necessary.
	byte[] sig = new byte[siglen];
	Boolean writeR = false;
	Boolean writeS = false;
	for (int i = 0; i < siglen; i++) {
		if (i < rslen) {
			if (!writeR)
				writeR = rb.length >= rslen - i;
			sig[i] = (writeR) ? rb[i] : (byte) 0x0;
		} else {
			int j = i - rslen; // Rebase.
			if (!writeS)
				writeS = sb.length >= rslen - j;
			sig[i] = (writeS) ? sb[j] : (byte) 0x0;
		}
	}
	return sig;
}
 
开发者ID:BoogieMAN2K,项目名称:Beem,代码行数:52,代码来源:OtrCryptoEngineImpl.java


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