当前位置: 首页>>代码示例>>Java>>正文


Java RSAPublicKey.getPublicExponent方法代码示例

本文整理汇总了Java中java.security.interfaces.RSAPublicKey.getPublicExponent方法的典型用法代码示例。如果您正苦于以下问题:Java RSAPublicKey.getPublicExponent方法的具体用法?Java RSAPublicKey.getPublicExponent怎么用?Java RSAPublicKey.getPublicExponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.interfaces.RSAPublicKey的用法示例。


在下文中一共展示了RSAPublicKey.getPublicExponent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: verify

import java.security.interfaces.RSAPublicKey; //导入方法依赖的package包/类
private static String verify() throws Exception {
	RSAEngine engine = new RSAEngine();
	Digest digest = new SHA1Digest();

	RSAPublicKey publicKey = (RSAPublicKey) getPublic(publicKeyFilename);
	BigInteger big = ((RSAKey) publicKey).getModulus();
	RSAKeyParameters rsaPublic = new RSAKeyParameters(false, big, publicKey.getPublicExponent());
	ISO9796d2Signer verifier = new ISO9796d2Signer(engine, digest, true);
	verifier.init(false, rsaPublic); // false for verify

	if (!verifier.verifySignature(signature)) {
		System.err.println("Signature was modified, could not verify correctness!");
		return "";
	}
	String recoveredMessage = "";
	try {
		if (verifier.hasFullMessage()) {
			verifier.updateWithRecoveredMessage(signature);

		}
		byte[] message = verifier.getRecoveredMessage();
		recoveredMessage = new String(message, "UTF-8");
	} catch (Exception exception) {
		System.err.println("Recover failed!");
	}

	return recoveredMessage;
}
 
开发者ID:true-gler,项目名称:ISO9796SignerVerifier,代码行数:29,代码来源:App.java

示例6: JCERSAPublicKey

import java.security.interfaces.RSAPublicKey; //导入方法依赖的package包/类
JCERSAPublicKey(
    RSAPublicKey key)
{
    this.modulus = key.getModulus();
    this.publicExponent = key.getPublicExponent();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:7,代码来源:JCERSAPublicKey.java

示例7: 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

示例8: BCRSAPublicKey

import java.security.interfaces.RSAPublicKey; //导入方法依赖的package包/类
BCRSAPublicKey(
    RSAPublicKey key)
{
    this.modulus = key.getModulus();
    this.publicExponent = key.getPublicExponent();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:7,代码来源:BCRSAPublicKey.java

示例9: 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

示例10: 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.getPublicExponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。