1package org.bouncycastle.crypto.params; 2 3import java.math.BigInteger; 4 5public class RSAKeyParameters 6 extends AsymmetricKeyParameter 7{ 8 private static final BigInteger ONE = BigInteger.valueOf(1); 9 10 private BigInteger modulus; 11 private BigInteger exponent; 12 13 public RSAKeyParameters( 14 boolean isPrivate, 15 BigInteger modulus, 16 BigInteger exponent) 17 { 18 super(isPrivate); 19 20 if (!isPrivate) 21 { 22 if ((exponent.intValue() & 1) == 0) 23 { 24 throw new IllegalArgumentException("RSA publicExponent is even"); 25 } 26 } 27 28 this.modulus = validate(modulus); 29 this.exponent = exponent; 30 } 31 32 private BigInteger validate(BigInteger modulus) 33 { 34 if ((modulus.intValue() & 1) == 0) 35 { 36 throw new IllegalArgumentException("RSA modulus is even"); 37 } 38 39 // the value is the product of the 132 smallest primes from 3 to 751 40 if (!modulus.gcd(new BigInteger("145188775577763990151158743208307020242261438098488931355057091965" + 41 "931517706595657435907891265414916764399268423699130577757433083166" + 42 "651158914570105971074227669275788291575622090199821297575654322355" + 43 "049043101306108213104080801056529374892690144291505781966373045481" + 44 "8359472391642885328171302299245556663073719855")).equals(ONE)) 45 { 46 throw new IllegalArgumentException("RSA modulus has a small prime factor"); 47 } 48 49 // TODO: add additional primePower/Composite test - expensive!! 50 51 return modulus; 52 } 53 54 public BigInteger getModulus() 55 { 56 return modulus; 57 } 58 59 public BigInteger getExponent() 60 { 61 return exponent; 62 } 63} 64