本文整理汇总了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;
}
示例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);
}
}
示例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");
}
}
示例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);
}
示例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.");
}
示例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.");
}
示例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);
}
示例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);
}
示例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();
}
示例10: JDKDSAPrivateKey
import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
JDKDSAPrivateKey(
DSAPrivateKey key)
{
this.x = key.getX();
this.dsaSpec = key.getParams();
}
示例11: BCDSAPrivateKey
import java.security.interfaces.DSAPrivateKey; //导入方法依赖的package包/类
BCDSAPrivateKey(
DSAPrivateKey key)
{
this.x = key.getX();
this.dsaSpec = key.getParams();
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}