本文整理汇总了Java中java.security.interfaces.RSAPrivateCrtKey.getModulus方法的典型用法代码示例。如果您正苦于以下问题:Java RSAPrivateCrtKey.getModulus方法的具体用法?Java RSAPrivateCrtKey.getModulus怎么用?Java RSAPrivateCrtKey.getModulus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.interfaces.RSAPrivateCrtKey
的用法示例。
在下文中一共展示了RSAPrivateCrtKey.getModulus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadPublicKeyFromKeyStore
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
/**
* 从KeyStore获取公钥
* @param location
* @param alias
* @param storeType
* @param storePass
* @param keyPass
* @return
*/
public static PublicKey loadPublicKeyFromKeyStore(String location, String alias, String storeType, String storePass, String keyPass) {
try {
storeType = null == storeType ? KeyStore.getDefaultType() : storeType;
keyPass = keyPass == null ? storePass : keyPass;
KeyStore keyStore = KeyStore.getInstance(storeType);
InputStream is = new FileInputStream(location);
keyStore.load(is, storePass.toCharArray());
RSAPrivateCrtKey key = (RSAPrivateCrtKey) keyStore.getKey(alias, keyPass.toCharArray());
RSAPublicKeySpec spec = new RSAPublicKeySpec(key.getModulus(),
key.getPublicExponent());
PublicKey publicKey = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(spec);
return publicKey;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: loadPublicKeyFromKeyStore
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
/**
* 从KeyStore获取公钥
* @param location
* @param alias
* @param storeType
* @param storePass
* @param keyPass
* @return
*/
public static PublicKey loadPublicKeyFromKeyStore(String location,String alias,String storeType,String storePass,String keyPass){
try {
storeType = null == storeType ? KeyStore.getDefaultType() : storeType;
keyPass = keyPass == null ? storePass : keyPass;
KeyStore keyStore = KeyStore.getInstance(storeType);
InputStream is = new FileInputStream(location);
keyStore.load(is, storePass.toCharArray());
RSAPrivateCrtKey key = (RSAPrivateCrtKey) keyStore.getKey(alias, keyPass.toCharArray());
RSAPublicKeySpec spec = new RSAPublicKeySpec(key.getModulus(),
key.getPublicExponent());
PublicKey publicKey = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(spec);
return publicKey;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: getPublicKey
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的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: loadKeyPair
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
private static KeyPair loadKeyPair(RSAPrivateCrtKey privatekey)
throws CertificateException {
try {
RSAPrivateCrtKey k = (RSAPrivateCrtKey) privatekey;
KeyFactory keyMaker = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(k.getModulus(),
k.getPublicExponent());
RSAPublicKey pubKey = (RSAPublicKey) keyMaker
.generatePublic(pubKeySpec);
return new KeyPair(pubKey, k);
} catch (Exception e) {
throw new CertificateException(
"Failed to convert RSAPrivateCrtKey into JCE KeyPair", e);
}
}
示例5: JCERSAPrivateCrtKey
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
/**
* construct a private key from another RSAPrivateCrtKey.
*
* @param key the object implementing the RSAPrivateCrtKey interface.
*/
JCERSAPrivateCrtKey(
RSAPrivateCrtKey key)
{
this.modulus = key.getModulus();
this.publicExponent = key.getPublicExponent();
this.privateExponent = key.getPrivateExponent();
this.primeP = key.getPrimeP();
this.primeQ = key.getPrimeQ();
this.primeExponentP = key.getPrimeExponentP();
this.primeExponentQ = key.getPrimeExponentQ();
this.crtCoefficient = key.getCrtCoefficient();
}
示例6: BCRSAPrivateCrtKey
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
/**
* construct a private key from another RSAPrivateCrtKey.
*
* @param key the object implementing the RSAPrivateCrtKey interface.
*/
BCRSAPrivateCrtKey(
RSAPrivateCrtKey key)
{
this.modulus = key.getModulus();
this.publicExponent = key.getPublicExponent();
this.privateExponent = key.getPrivateExponent();
this.primeP = key.getPrimeP();
this.primeQ = key.getPrimeQ();
this.primeExponentP = key.getPrimeExponentP();
this.primeExponentQ = key.getPrimeExponentQ();
this.crtCoefficient = key.getCrtCoefficient();
}
示例7: generateRSAPrivateKeyParameter
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
public static RSAKeyParameters generateRSAPrivateKeyParameter(RSAPrivateKey key) {
ParamUtil.requireNonNull("key", key);
if (key instanceof RSAPrivateCrtKey) {
RSAPrivateCrtKey rsaKey = (RSAPrivateCrtKey) key;
return new RSAPrivateCrtKeyParameters(rsaKey.getModulus(), rsaKey.getPublicExponent(),
rsaKey.getPrivateExponent(), rsaKey.getPrimeP(), rsaKey.getPrimeQ(),
rsaKey.getPrimeExponentP(), rsaKey.getPrimeExponentQ(),
rsaKey.getCrtCoefficient());
} else {
return new RSAKeyParameters(true, key.getModulus(), key.getPrivateExponent());
}
}
示例8: getRSASignerCredentials
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
protected TlsSignerCredentials getRSASignerCredentials() throws IOException {
RSAPrivateCrtKey key = (RSAPrivateCrtKey)(pair.getValue().getPrivate());
return new DefaultTlsSignerCredentials(context,
cert,
new RSAKeyParameters(true,key.getModulus(),key.getPrivateExponent()),
new SignatureAndHashAlgorithm(HashAlgorithm.sha256,SignatureAlgorithm.rsa));
}
示例9: TempJCERSAPrivateCrtKey
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
/**
* construct a private key from another RSAPrivateCrtKey.
*
* @param key the object implementing the RSAPrivateCrtKey interface.
*/
TempJCERSAPrivateCrtKey(
RSAPrivateCrtKey key)
{
this.modulus = key.getModulus();
this.publicExponent = key.getPublicExponent();
this.privateExponent = key.getPrivateExponent();
this.primeP = key.getPrimeP();
this.primeQ = key.getPrimeQ();
this.primeExponentP = key.getPrimeExponentP();
this.primeExponentQ = key.getPrimeExponentQ();
this.crtCoefficient = key.getCrtCoefficient();
}
示例10: checkPrivateCrtKey
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
private void checkPrivateCrtKey(RSAPrivateCrtKey key, int expectedKeySize) throws Exception {
BigInteger p = key.getPrimeP();
BigInteger q = key.getPrimeQ();
BigInteger n = key.getModulus();
BigInteger e = key.getPublicExponent();
BigInteger d = key.getPrivateExponent();
BigInteger dp = key.getPrimeExponentP();
BigInteger dq = key.getPrimeExponentQ();
BigInteger crtCoeff = key.getCrtCoefficient();
// Simple test that (n,d,e) is a valid RSA key.
assertEquals(n, p.multiply(q));
assertEquals(expectedKeySize, n.bitLength());
int certainty = 80;
assertTrue(p.isProbablePrime(certainty));
assertTrue(q.isProbablePrime(certainty));
// Very simple checks for weak random number generators.
RandomUtil.checkPrime(p);
RandomUtil.checkPrime(q);
assertTrue(d.bitLength() > expectedKeySize / 2);
// TODO(bleichen): Keys that are very imbalanced can be broken with elliptic curve factoring.
// Add other checks. E.g. for the size of dp and dq
assertTrue(p.bitLength() > 256);
assertTrue(q.bitLength() > 256);
BigInteger p1 = p.subtract(BigInteger.ONE);
BigInteger q1 = q.subtract(BigInteger.ONE);
BigInteger phi = p1.multiply(q1);
BigInteger order = phi.divide(p1.gcd(q1)); // maximal order of elements
assertEquals(BigInteger.ONE, d.multiply(e).mod(order));
assertEquals(d.mod(p1), dp.mod(p1));
assertEquals(d.mod(q1), dq.mod(q1));
assertEquals(q.multiply(crtCoeff).mod(p), BigInteger.ONE);
}
示例11: getPrivateKeyParameters
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
private RSAPrivateCrtKeyParameters getPrivateKeyParameters(RSAPrivateCrtKey privateCrtKey) {
return new RSAPrivateCrtKeyParameters(privateCrtKey.getModulus(),
privateCrtKey.getPublicExponent(),
privateCrtKey.getPrivateExponent(),
privateCrtKey.getPrimeP(), privateCrtKey.getPrimeQ(), privateCrtKey.getPrimeExponentP(),
privateCrtKey.getPrimeExponentQ(),
privateCrtKey.getCrtCoefficient());
}
示例12: recoverPubkey
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
private static RSAPublicKey recoverPubkey(RSAPrivateKey privateKey) {
RSAPrivateCrtKey certKey = (RSAPrivateCrtKey) privateKey;
BigInteger pubExponent = certKey.getPublicExponent();
BigInteger modulus = certKey.getModulus();
RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(modulus, pubExponent);
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
return (RSAPublicKey) keyFactory.generatePublic(pubSpec);
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException e) {
km_log.e("Error while recovering public key from private key!");
e.printStackTrace();
}
return null;
}
示例13: init_sig_keys
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
private void init_sig_keys() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException{
if(init_sig) return;
sig = Signature.getInstance("SHA1WithRSA");
sigPvk=(PrivateKey)readPEMKey(new File("private.key.pkcs8"));
RSAPrivateCrtKey privk = (RSAPrivateCrtKey)sigPvk;
RSAPublicKeySpec publicKeySpec = new java.security.spec.RSAPublicKeySpec(privk.getModulus(),privk.getPublicExponent());
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
sigPuk = keyFactory.generatePublic(publicKeySpec);
sig.initSign(sigPvk);
/*Verifica che funzi
byte[] b=new byte[]{1, 2, 3,4,5};
try {
sig.update(b);
byte[] bb=sig.sign();
sig.initVerify(sigPuk);
sig.update(b);
System.out.println("Funziona: "+ sig.verify(bb));
} catch (SignatureException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
init_sig=true;
}
示例14: publicKeyFromPrivateKey
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
@Override
public PublicKey publicKeyFromPrivateKey(PrivateKey privateKey, KeyFactory keyFactory)
throws InvalidKeySpecException {
RSAPrivateCrtKey rsaPrivateKey = (RSAPrivateCrtKey) privateKey;
RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(
rsaPrivateKey.getModulus(), rsaPrivateKey.getPublicExponent());
return keyFactory.generatePublic(publicKeySpec);
}
示例15: buildChain
import java.security.interfaces.RSAPrivateCrtKey; //导入方法依赖的package包/类
/**
* Builds the chain up such that chain[ 0 ] contains the public key
* corresponding to the supplied private key.
*
* @param key private key
* @param chain array of certificates to build chain from
* @return theOne!
* @throws java.security.KeyStoreException no certificates correspond to private key
* @throws java.security.cert.CertificateException java libraries complaining
* @throws java.security.NoSuchAlgorithmException java libraries complaining
* @throws java.security.InvalidKeyException java libraries complaining
* @throws java.security.NoSuchProviderException java libraries complaining
*/
public static X509Certificate buildChain(Key key, Certificate[] chain)
throws CertificateException, KeyStoreException,
NoSuchAlgorithmException, InvalidKeyException,
NoSuchProviderException {
X509Certificate theOne = null;
if (key instanceof RSAPrivateCrtKey) {
final RSAPrivateCrtKey rsa = (RSAPrivateCrtKey) key;
BigInteger publicExponent = rsa.getPublicExponent();
BigInteger modulus = rsa.getModulus();
for (int i = 0; i < chain.length; i++) {
X509Certificate c = (X509Certificate) chain[i];
PublicKey pub = c.getPublicKey();
if (pub instanceof RSAPublicKey) {
RSAPublicKey certKey = (RSAPublicKey) pub;
BigInteger pe = certKey.getPublicExponent();
BigInteger mod = certKey.getModulus();
if (publicExponent.equals(pe) && modulus.equals(mod)) {
theOne = c;
}
}
}
if (theOne == null) {
throw new KeyStoreException("Can't build keystore: [No certificates belong to the private-key]");
}
X509Certificate[] newChain;
newChain = X509CertificateChainBuilder.buildPath(theOne, chain);
Arrays.fill(chain, null);
System.arraycopy(newChain, 0, chain, 0, newChain.length);
}
return theOne;
}