本文整理汇总了Java中org.bouncycastle.bcpg.RSAPublicBCPGKey类的典型用法代码示例。如果您正苦于以下问题:Java RSAPublicBCPGKey类的具体用法?Java RSAPublicBCPGKey怎么用?Java RSAPublicBCPGKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RSAPublicBCPGKey类属于org.bouncycastle.bcpg包,在下文中一共展示了RSAPublicBCPGKey类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.bouncycastle.bcpg.RSAPublicBCPGKey; //导入依赖的package包/类
private void init(KeyFingerPrintCalculator fingerPrintCalculator)
throws PGPException
{
BCPGKey key = publicPk.getKey();
this.fingerprint = fingerPrintCalculator.calculateFingerprint(publicPk);
if (publicPk.getVersion() <= 3)
{
RSAPublicBCPGKey rK = (RSAPublicBCPGKey)key;
this.keyID = rK.getModulus().longValue();
this.keyStrength = rK.getModulus().bitLength();
}
else
{
this.keyID = ((long)(fingerprint[fingerprint.length - 8] & 0xff) << 56)
| ((long)(fingerprint[fingerprint.length - 7] & 0xff) << 48)
| ((long)(fingerprint[fingerprint.length - 6] & 0xff) << 40)
| ((long)(fingerprint[fingerprint.length - 5] & 0xff) << 32)
| ((long)(fingerprint[fingerprint.length - 4] & 0xff) << 24)
| ((long)(fingerprint[fingerprint.length - 3] & 0xff) << 16)
| ((long)(fingerprint[fingerprint.length - 2] & 0xff) << 8)
| ((fingerprint[fingerprint.length - 1] & 0xff));
if (key instanceof RSAPublicBCPGKey)
{
this.keyStrength = ((RSAPublicBCPGKey)key).getModulus().bitLength();
}
else if (key instanceof DSAPublicBCPGKey)
{
this.keyStrength = ((DSAPublicBCPGKey)key).getP().bitLength();
}
else if (key instanceof ElGamalPublicBCPGKey)
{
this.keyStrength = ((ElGamalPublicBCPGKey)key).getP().bitLength();
}
}
}
示例2: checkWeakKey
import org.bouncycastle.bcpg.RSAPublicBCPGKey; //导入依赖的package包/类
private final static void checkWeakKey(PGPPublicKey pk)
throws PGPException
{
BCPGKey k = pk.getPublicKeyPacket().getKey();
if (k instanceof RSAPublicBCPGKey) {
checkWeakRSA((RSAPublicBCPGKey) k);
}
else if (k instanceof DSAPublicBCPGKey) {
checkDSA((DSAPublicBCPGKey) k);
}
// tbd
}
示例3: checkWeakRSA
import org.bouncycastle.bcpg.RSAPublicBCPGKey; //导入依赖的package包/类
private final static void checkWeakRSA(RSAPublicBCPGKey rsak)
throws PGPException
{
BigInteger n = rsak.getModulus();
BigInteger e = rsak.getPublicExponent();
// n and e should be odd.
if (!n.testBit(0) || !e.testBit(0)) {
throw new PGPException("modulus and exponent must not be even.");
}
// e should be > 2
if (e.compareTo(TWO) <= 0) {
throw new PGPException("exponent must be >= 3");
}
// modulus should fail primality test
if (n.isProbablePrime(80)) {
throw new PGPException
("modulus doesn't seem to be a composite number.");
}
// modulus should have no small factors
BigInteger factor = n.gcd(SMALL_FACTORS);
if (!factor.equals(BigInteger.ONE)) {
throw new PGPException("modulus has a small factor ("+factor+")");
}
}