本文整理汇总了Java中java.security.interfaces.DSAParams.getG方法的典型用法代码示例。如果您正苦于以下问题:Java DSAParams.getG方法的具体用法?Java DSAParams.getG怎么用?Java DSAParams.getG使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.interfaces.DSAParams
的用法示例。
在下文中一共展示了DSAParams.getG方法的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: 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);
}
示例6: 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());
}
示例7: 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);
}
示例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());
super.init(spec, random, false);
}
示例9: 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");
}
示例10: 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;
}
示例11: 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;
}
示例12: 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);
}
示例13: initVerify
import java.security.interfaces.DSAParams; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void initVerify() {
if (verifyKey == null) {
throw new IllegalStateException(
"Verify key must be set prior to initialization.");
}
final DSAPublicKey pubKey = (DSAPublicKey) verifyKey;
final DSAParams params = pubKey.getParams();
final DSAPublicKeyParameters bcParams = new DSAPublicKeyParameters(
pubKey.getY(), new DSAParameters(params.getP(), params.getQ(),
params.getG()));
init(false, bcParams);
}
示例14: 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, g, x;
int n;
if (privateKey == null || !(privateKey instanceof DSAPrivateKey)) {
throw new InvalidKeyException(
Messages.getString("security.168")); //$NON-NLS-1$
}
params = ((DSAPrivateKey) privateKey).getParams();
p = params.getP();
q = params.getQ();
g = params.getG();
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(Messages.getString("security.169")); //$NON-NLS-1$
}
if (q.signum() != 1 && q.bitLength() != 160) {
throw new InvalidKeyException(Messages.getString("security.16A")); //$NON-NLS-1$
}
if (x.signum() != 1 || x.compareTo(q) != -1) {
throw new InvalidKeyException(Messages.getString("security.16B")); //$NON-NLS-1$
}
dsaKey = (DSAKey) privateKey;
msgDigest.reset();
}
示例15: 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, g, y;
int n1;
if (publicKey == null || !(publicKey instanceof DSAPublicKey)) {
throw new InvalidKeyException(
Messages.getString("security.16C")); //$NON-NLS-1$
}
DSAParams params = ((DSAPublicKey) publicKey).getParams();
p = params.getP();
q = params.getQ();
g = params.getG();
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(Messages.getString("security.169")); //$NON-NLS-1$
}
if (q.signum() != 1 || q.bitLength() != 160) {
throw new InvalidKeyException(Messages.getString("security.16A")); //$NON-NLS-1$
}
if (y.signum() != 1) {
throw new InvalidKeyException(Messages.getString("security.16D")); //$NON-NLS-1$
}
dsaKey = (DSAKey) publicKey;
msgDigest.reset();
}