本文整理汇总了Java中java.security.interfaces.DSAParams.getQ方法的典型用法代码示例。如果您正苦于以下问题:Java DSAParams.getQ方法的具体用法?Java DSAParams.getQ怎么用?Java DSAParams.getQ使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.interfaces.DSAParams
的用法示例。
在下文中一共展示了DSAParams.getQ方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeInheritedParamsKey
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/**
* Internal method to create a new key with inherited key parameters.
*
* @param keyValueKey key from which to obtain key value
* @param keyParamsKey key from which to obtain key parameters
* @return new public key having value and parameters
* @throws CertPathValidatorException if keys are not appropriate types
* for this operation
*/
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
PublicKey keyParamsKey) throws CertPathValidatorException
{
if (!(keyValueKey instanceof DSAPublicKey) ||
!(keyParamsKey instanceof DSAPublicKey))
throw new CertPathValidatorException("Input key is not " +
"appropriate type for " +
"inheriting parameters");
DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
if (params == null)
throw new CertPathValidatorException("Key parameters missing");
try {
BigInteger y = ((DSAPublicKey)keyValueKey).getY();
KeyFactory kf = KeyFactory.getInstance("DSA");
DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
params.getP(),
params.getQ(),
params.getG());
return kf.generatePublic(ks);
} catch (GeneralSecurityException e) {
throw new CertPathValidatorException("Unable to generate key with" +
" inherited parameters: " +
e.getMessage(), e);
}
}
示例2: regenerateLocalPublicKey
import java.security.interfaces.DSAParams; //导入方法依赖的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.DSAParams; //导入方法依赖的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: DOMKeyValue
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
public DOMKeyValue(PublicKey key) throws KeyException {
if (key == null) {
throw new NullPointerException("key cannot be null");
}
this.publicKey = key;
if (key instanceof DSAPublicKey) {
DSAPublicKey dkey = (DSAPublicKey) key;
DSAParams params = dkey.getParams();
p = new DOMCryptoBinary(params.getP());
q = new DOMCryptoBinary(params.getQ());
g = new DOMCryptoBinary(params.getG());
y = new DOMCryptoBinary(dkey.getY());
} else if (key instanceof RSAPublicKey) {
RSAPublicKey rkey = (RSAPublicKey) key;
exponent = new DOMCryptoBinary(rkey.getPublicExponent());
modulus = new DOMCryptoBinary(rkey.getModulus());
} else {
throw new KeyException("unsupported key algorithm: " +
key.getAlgorithm());
}
}
示例5: regenerateLocalPublicKey
import java.security.interfaces.DSAParams; //导入方法依赖的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);
}
示例6: initialize
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/**
* Initializes the DSA object using a DSA parameter object.
*
* @param params a fully initialized DSA parameter object.
*/
public void initialize(DSAParams params, SecureRandom random) {
if (params == null) {
throw new InvalidParameterException("Params must not be null");
}
DSAParameterSpec spec = new DSAParameterSpec
(params.getP(), params.getQ(), params.getG());
initialize0(spec, random);
}
示例7: DSA
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
DSA(PublicKey key) throws KeyException {
super(key);
DSAPublicKey dkey = (DSAPublicKey) key;
DSAParams params = dkey.getParams();
p = new DOMCryptoBinary(params.getP());
q = new DOMCryptoBinary(params.getQ());
g = new DOMCryptoBinary(params.getG());
y = new DOMCryptoBinary(dkey.getY());
}
示例8: initialize
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/**
* Initializes the DSA object using a DSA parameter object.
*
* @param params a fully initialized DSA parameter object.
*/
@Override
public void initialize(DSAParams params, SecureRandom random)
throws InvalidParameterException {
if (params == null) {
throw new InvalidParameterException("Params must not be null");
}
DSAParameterSpec spec = new DSAParameterSpec
(params.getP(), params.getQ(), params.getG());
initialize0(spec, random);
}
示例9: initialize
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/**
* Initializes the DSA object using a DSA parameter object.
*
* @param params a fully initialized DSA parameter object.
*/
@Override
public void initialize(DSAParams params, SecureRandom random)
throws InvalidParameterException {
if (params == null) {
throw new InvalidParameterException("Params must not be null");
}
DSAParameterSpec spec = new DSAParameterSpec
(params.getP(), params.getQ(), params.getG());
super.init(spec, random, false);
}
示例10: convertToTrilead
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
public static Object convertToTrilead(PublicKey pk) {
if (pk instanceof RSAPublicKey) {
return new com.trilead.ssh2.signature.RSAPublicKey(
((RSAPublicKey) pk).getPublicExponent(),
((RSAPublicKey) pk).getModulus());
} else if (pk instanceof DSAPublicKey) {
DSAParams dp = ((DSAPublicKey) pk).getParams();
return new com.trilead.ssh2.signature.DSAPublicKey(
dp.getP(), dp.getQ(), dp.getG(), ((DSAPublicKey) pk).getY());
}
throw new IllegalArgumentException("PublicKey is not RSA or DSA format");
}
示例11: verify
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
private Boolean verify(byte[] b, PublicKey pubKey, BigInteger r, BigInteger s)
throws OtrCryptoException {
if (!(pubKey instanceof DSAPublicKey))
throw new IllegalArgumentException();
DSAParams dsaParams = ((DSAPublicKey) pubKey).getParams();
BigInteger q = dsaParams.getQ();
DSAParameters bcDSAParams = new DSAParameters(dsaParams.getP(), q, dsaParams.getG());
DSAPublicKey dsaPrivateKey = (DSAPublicKey) pubKey;
DSAPublicKeyParameters dsaPrivParms = new DSAPublicKeyParameters(dsaPrivateKey.getY(),
bcDSAParams);
// 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
DSASigner dsaSigner = new DSASigner();
dsaSigner.init(false, dsaPrivParms);
BigInteger bmpi = new BigInteger(1, b);
Boolean result = dsaSigner.verifySignature(BigIntegers.asUnsignedByteArray(bmpi.mod(q)), r,
s);
return result;
}
示例12: engineInitSign
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/**
* Initializes this signature object with PrivateKey object
* passed as argument to the method.
*
* @params
* privateKey DSAPrivateKey object
* @throws
* InvalidKeyException if privateKey is not DSAPrivateKey object
*/
protected void engineInitSign(PrivateKey privateKey)
throws InvalidKeyException {
DSAParams params;
// parameters and private key
BigInteger p, q, x;
int n;
if (privateKey == null || !(privateKey instanceof DSAPrivateKey)) {
throw new InvalidKeyException();
}
params = ((DSAPrivateKey) privateKey).getParams();
p = params.getP();
q = params.getQ();
x = ((DSAPrivateKey) privateKey).getX();
// checks described in DSA standard
n = p.bitLength();
if (p.compareTo(BigInteger.valueOf(1)) != 1 || n < 512 || n > 1024 || (n & 077) != 0) {
throw new InvalidKeyException("bad p");
}
if (q.signum() != 1 && q.bitLength() != 160) {
throw new InvalidKeyException("bad q");
}
if (x.signum() != 1 || x.compareTo(q) != -1) {
throw new InvalidKeyException("x <= 0 || x >= q");
}
dsaKey = (DSAKey) privateKey;
msgDigest.reset();
}
示例13: engineInitVerify
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/**
* Initializes this signature object with PublicKey object
* passed as argument to the method.
*
* @params
* publicKey DSAPublicKey object
* @throws
* InvalidKeyException if publicKey is not DSAPublicKey object
*/
protected void engineInitVerify(PublicKey publicKey)
throws InvalidKeyException {
// parameters and public key
BigInteger p, q, y;
int n1;
if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
throw new InvalidKeyException("publicKey is not an instance of DSAPublicKey");
}
DSAParams params = ((DSAPublicKey) publicKey).getParams();
p = params.getP();
q = params.getQ();
y = ((DSAPublicKey) publicKey).getY();
// checks described in DSA standard
n1 = p.bitLength();
if (p.compareTo(BigInteger.valueOf(1)) != 1 || n1 < 512 || n1 > 1024 || (n1 & 077) != 0) {
throw new InvalidKeyException("bad p");
}
if (q.signum() != 1 || q.bitLength() != 160) {
throw new InvalidKeyException("bad q");
}
if (y.signum() != 1) {
throw new InvalidKeyException("y <= 0");
}
dsaKey = (DSAKey) publicKey;
msgDigest.reset();
}
示例14: makeInheritedParamsKey
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/**
* Internal method to create a new key with inherited key parameters
*
* @param keyValueKey key from which to obtain key value
* @param keyParamsKey key from which to obtain key parameters
* @return new public key having value and parameters
* @throws CertPathValidatorException if keys are not appropriate types
* for this operation
*/
static PublicKey makeInheritedParamsKey(PublicKey keyValueKey,
PublicKey keyParamsKey) throws CertPathValidatorException
{
PublicKey usableKey;
if (!(keyValueKey instanceof DSAPublicKey) ||
!(keyParamsKey instanceof DSAPublicKey))
throw new CertPathValidatorException("Input key is not " +
"appropriate type for " +
"inheriting parameters");
DSAParams params = ((DSAPublicKey)keyParamsKey).getParams();
if (params == null)
throw new CertPathValidatorException("Key parameters missing");
try {
BigInteger y = ((DSAPublicKey)keyValueKey).getY();
KeyFactory kf = KeyFactory.getInstance("DSA");
DSAPublicKeySpec ks = new DSAPublicKeySpec(y,
params.getP(),
params.getQ(),
params.getG());
usableKey = kf.generatePublic(ks);
} catch (GeneralSecurityException e) {
throw new CertPathValidatorException("Unable to generate key with" +
" inherited parameters: " +
e.getMessage(), e);
}
return usableKey;
}
示例15: initSign
import java.security.interfaces.DSAParams; //导入方法依赖的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);
}