本文整理匯總了Java中java.security.interfaces.RSAPrivateCrtKey.getPublicExponent方法的典型用法代碼示例。如果您正苦於以下問題:Java RSAPrivateCrtKey.getPublicExponent方法的具體用法?Java RSAPrivateCrtKey.getPublicExponent怎麽用?Java RSAPrivateCrtKey.getPublicExponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.interfaces.RSAPrivateCrtKey
的用法示例。
在下文中一共展示了RSAPrivateCrtKey.getPublicExponent方法的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: 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();
}
示例9: 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);
}
示例10: 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());
}
示例11: 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;
}
示例12: 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;
}
示例13: 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);
}
示例14: 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;
}
示例15: main
import java.security.interfaces.RSAPrivateCrtKey; //導入方法依賴的package包/類
public static void main(String[] args) throws NoSuchAlgorithmException,
NoSuchProviderException, InvalidKeySpecException {
// Generate the first key.
KeyPairGenerator generator
= KeyPairGenerator.getInstance(KEYALG, PROVIDER_NAME);
KeyPair keyPair = generator.generateKeyPair();
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
if (!(rsaPrivateKey instanceof RSAPrivateCrtKey)) {
System.err.println("rsaPrivateKey class : " + rsaPrivateKey.getClass().getName());
throw new RuntimeException("rsaPrivateKey is not a RSAPrivateCrtKey instance");
}
// Generate the second key.
KeyFactory factory = KeyFactory.getInstance(KEYALG, PROVIDER_NAME);
RSAPrivateKeySpec rsaPrivateKeySpec = new RSAPrivateKeySpec(
rsaPrivateKey.getModulus(), rsaPrivateKey.getPrivateExponent());
RSAPrivateKey rsaPrivateKey2 = (RSAPrivateKey) factory.generatePrivate(
rsaPrivateKeySpec);
// Generate the third key.
PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(
rsaPrivateKey.getEncoded());
RSAPrivateKey rsaPrivateKey3 = (RSAPrivateKey) factory.generatePrivate(
encodedKeySpec);
// Check for equality.
if (rsaPrivateKey.equals(rsaPrivateKey2)) {
throw new RuntimeException("rsaPrivateKey should not equal to rsaPrivateKey2");
}
if (!rsaPrivateKey3.equals(rsaPrivateKey)) {
throw new RuntimeException("rsaPrivateKey3 should equal to rsaPrivateKey");
}
if (rsaPrivateKey3.equals(rsaPrivateKey2)) {
throw new RuntimeException("rsaPrivateKey3 should not equal to rsaPrivateKey2");
}
if (rsaPrivateKey2.equals(rsaPrivateKey3)) {
throw new RuntimeException("rsaPrivateKey2 should not equal to rsaPrivateKey3");
}
// Generate the fourth key.
RSAPrivateCrtKey rsaPrivateCrtKey = (RSAPrivateCrtKey)rsaPrivateKey;
RSAPrivateCrtKeySpec rsaPrivateCrtKeySpec = new RSAPrivateCrtKeySpec(
rsaPrivateCrtKey.getModulus(),
rsaPrivateCrtKey.getPublicExponent(),
rsaPrivateCrtKey.getPrivateExponent(),
rsaPrivateCrtKey.getPrimeP(),
rsaPrivateCrtKey.getPrimeQ(),
rsaPrivateCrtKey.getPrimeExponentP(),
rsaPrivateCrtKey.getPrimeExponentQ(),
rsaPrivateCrtKey.getCrtCoefficient()
);
RSAPrivateCrtKey rsaPrivateKey4 = (RSAPrivateCrtKey) factory.generatePrivate(
rsaPrivateCrtKeySpec);
if (!rsaPrivateKey.equals(rsaPrivateKey4)) {
throw new RuntimeException("rsaPrivateKey should equal to rsaPrivateKey4");
}
}