當前位置: 首頁>>代碼示例>>Java>>正文


Java RSAPublicKey.getModulus方法代碼示例

本文整理匯總了Java中java.security.interfaces.RSAPublicKey.getModulus方法的典型用法代碼示例。如果您正苦於以下問題:Java RSAPublicKey.getModulus方法的具體用法?Java RSAPublicKey.getModulus怎麽用?Java RSAPublicKey.getModulus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.interfaces.RSAPublicKey的用法示例。


在下文中一共展示了RSAPublicKey.getModulus方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decrypt

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
public static String decrypt(PublicKey publicKey, String cipherText)
		throws Exception {
	Cipher cipher = Cipher.getInstance("RSA");
	try {
		cipher.init(Cipher.DECRYPT_MODE, publicKey);
	} catch (InvalidKeyException e) {
           // 因為 IBM JDK 不支持私鑰加密, 公鑰解密, 所以要反轉公私鑰
           // 也就是說對於解密, 可以通過公鑰的參數偽造一個私鑰對象欺騙 IBM JDK
           RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
           RSAPrivateKeySpec spec = new RSAPrivateKeySpec(rsaPublicKey.getModulus(), rsaPublicKey.getPublicExponent());
           Key fakePrivateKey = KeyFactory.getInstance("RSA").generatePrivate(spec);
           cipher = Cipher.getInstance("RSA"); //It is a stateful object. so we need to get new one.
           cipher.init(Cipher.DECRYPT_MODE, fakePrivateKey);
	}
	
	if (cipherText == null || cipherText.length() == 0) {
		return cipherText;
	}

	byte[] cipherBytes = Base64.base64ToByteArray(cipherText);
	byte[] plainBytes = cipher.doFinal(cipherBytes);

	return new String(plainBytes);
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:25,代碼來源:DecryptUtil.java

示例2: decrypt

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
public static String decrypt(PublicKey publicKey, String cipherText)
        throws Exception {
    Cipher cipher = Cipher.getInstance("RSA");
    try {
        cipher.init(Cipher.DECRYPT_MODE, publicKey);
    } catch (InvalidKeyException e) {
        //  IBM JDK not support Private key encryption, public key decryption
        // so fake an PrivateKey for it
        RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
        RSAPrivateKeySpec spec = new RSAPrivateKeySpec(rsaPublicKey.getModulus(), rsaPublicKey.getPublicExponent());
        Key fakePrivateKey = KeyFactory.getInstance("RSA").generatePrivate(spec);
        cipher = Cipher.getInstance("RSA"); //It is a stateful object. so we need to get new one.
        cipher.init(Cipher.DECRYPT_MODE, fakePrivateKey);
    }

    if (cipherText == null || cipherText.length() == 0) {
        return cipherText;
    }

    byte[] cipherBytes = Base64.base64ToByteArray(cipherText);
    byte[] plainBytes = cipher.doFinal(cipherBytes);

    return new String(plainBytes);
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:25,代碼來源:DecryptUtil.java

示例3: generatePublicKeyParameter

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey key)
        throws InvalidKeyException {
    ParamUtil.requireNonNull("key", key);

    if (key instanceof RSAPublicKey) {
        RSAPublicKey rsaKey = (RSAPublicKey) key;
        return new RSAKeyParameters(false, rsaKey.getModulus(), rsaKey.getPublicExponent());
    } else if (key instanceof ECPublicKey) {
        return ECUtil.generatePublicKeyParameter(key);
    } else if (key instanceof DSAPublicKey) {
        return DSAUtil.generatePublicKeyParameter(key);
    } else {
        throw new InvalidKeyException("unknown key " + key.getClass().getName());
    }
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:16,代碼來源:KeyUtil.java

示例4: getRSAPublicKeySpec

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
static RSAPublicKeySpec getRSAPublicKeySpec(PublicKey key) {
    if (key instanceof RSAPublicKey) {
        RSAPublicKey rsaKey = (RSAPublicKey)key;
        return new RSAPublicKeySpec(rsaKey.getModulus(),
                                    rsaKey.getPublicExponent());
    }
    try {
        KeyFactory factory = JsseJce.getKeyFactory("RSA");
        return factory.getKeySpec(key, RSAPublicKeySpec.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:JsseJce.java

示例5: JCERSAPublicKey

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
JCERSAPublicKey(
    RSAPublicKey key)
{
    this.modulus = key.getModulus();
    this.publicExponent = key.getPublicExponent();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:7,代碼來源:JCERSAPublicKey.java

示例6: generatePublicKeyParameter

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
static RSAKeyParameters generatePublicKeyParameter(
    RSAPublicKey key)
{
    return new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent());

}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:7,代碼來源:RSAUtil.java

示例7: BCRSAPublicKey

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
BCRSAPublicKey(
    RSAPublicKey key)
{
    this.modulus = key.getModulus();
    this.publicExponent = key.getPublicExponent();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:7,代碼來源:BCRSAPublicKey.java

示例8: RSA

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
RSA(PublicKey key) throws KeyException {
    super(key);
    RSAPublicKey rkey = (RSAPublicKey)key;
    exponent = new DOMCryptoBinary(rkey.getPublicExponent());
    modulus = new DOMCryptoBinary(rkey.getModulus());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:DOMKeyValue.java

示例9: generatePublicKeyParameter

import java.security.interfaces.RSAPublicKey; //導入方法依賴的package包/類
static public RSAKeyParameters generatePublicKeyParameter(
    RSAPublicKey    key)
{
    return new RSAKeyParameters(false, key.getModulus(), key.getPublicExponent());

}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:7,代碼來源:RSAUtil.java


注:本文中的java.security.interfaces.RSAPublicKey.getModulus方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。