本文整理匯總了Java中java.security.spec.RSAKeyGenParameterSpec.F4屬性的典型用法代碼示例。如果您正苦於以下問題:Java RSAKeyGenParameterSpec.F4屬性的具體用法?Java RSAKeyGenParameterSpec.F4怎麽用?Java RSAKeyGenParameterSpec.F4使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.security.spec.RSAKeyGenParameterSpec
的用法示例。
在下文中一共展示了RSAKeyGenParameterSpec.F4屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: LoginController
private LoginController() throws GeneralSecurityException
{
_log.info("Loading LoginContoller...");
_hackProtection = new HashMap<>();
_keyPairs = new ScrambledKeyPair[10];
KeyPairGenerator keygen = null;
keygen = KeyPairGenerator.getInstance("RSA");
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
keygen.initialize(spec);
//generate the initial set of keys
for (int i = 0; i < 10; i++)
{
_keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
}
_log.info("Cached 10 KeyPairs for RSA communication");
testCipher((RSAPrivateKey) _keyPairs[0]._pair.getPrivate());
// Store keys for blowfish communication
generateBlowFishKeys();
}
示例2: generateRSAKeypair
public static KeyPair generateRSAKeypair(int keysize, BigInteger publicExponent,
SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException,
InvalidAlgorithmParameterException {
BigInteger tmpPublicExponent = publicExponent;
if (tmpPublicExponent == null) {
tmpPublicExponent = RSAKeyGenParameterSpec.F4;
}
AlgorithmParameterSpec params = new RSAKeyGenParameterSpec(keysize, tmpPublicExponent);
KeyPairGenerator kpGen = getKeyPairGenerator("RSA");
synchronized (kpGen) {
if (random == null) {
kpGen.initialize(params);
} else {
kpGen.initialize(params, random);
}
return kpGen.generateKeyPair();
}
}
示例3: main
public static void main(String[] args) throws Exception {
int size = 0;
if (args.length >= 1) {
size = Integer.parseInt(args[0]);
} else {
throw new RuntimeException("Missing keysize to test with");
}
BigInteger publicExponent
= (args.length >= 2) ? new BigInteger(args[1]) : RSAKeyGenParameterSpec.F4;
System.out.println("Running test with key size: " + size
+ " and public exponent: " + publicExponent);
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
kpg1.initialize(new RSAKeyGenParameterSpec(size, publicExponent));
if (!specTest(kpg1.generateKeyPair(), publicExponent)) {
throw new RuntimeException("Test failed.");
}
}
示例4: CertRASession
public CertRASession(String emailPrivate, String phonePrivate) throws Exception {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
RSAKeyGenParameterSpec params = new RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4);
SecureRandom secureRandom = new SecureRandom();
secureRandom.setSeed(System.currentTimeMillis());
keyPairGenerator.initialize(params, secureRandom);
KeyPair keyPair = keyPairGenerator.genKeyPair();
this.privateKey = keyPair.getPrivate();
this.publicKey = keyPair.getPublic();
this.emailPrivate = emailPrivate;
this.phonePrivate = phonePrivate;
}
示例5: genKeys
private void genKeys(int keyLength, String folderName) {
if (keyLength > 0)
this.keyLength = keyLength;
if (folderName != null)
this.folderName = folderName;
if (!this.folderName.endsWith("/"))
this.folderName += "/";
System.out.printf("Generating %d-bit RSA keys in folder '%s'\n", this.keyLength, this.folderName);
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
// Generate a key that is keyLength bits long
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(this.keyLength, RSAKeyGenParameterSpec.F4);
keyGen.initialize(spec);
KeyPair pair = keyGen.generateKeyPair();
printKeyPair(pair);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: loadRSAKeys
private void loadRSAKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
{
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(512,RSAKeyGenParameterSpec.F4);
keyGen.initialize(spec);
_keyPairs = new KeyPair[KEYS_SIZE];
for (int i = 0; i < KEYS_SIZE; i++)
{
_keyPairs[i] = keyGen.genKeyPair();
}
}
示例7: LoginController
private LoginController() throws GeneralSecurityException
{
_log.info("Loading LoginController...");
_keyPairs = new ScrambledKeyPair[10];
final KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
final RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
keygen.initialize(spec);
// generate the initial set of keys
for (int i = 0; i < 10; i++)
{
_keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
}
_log.info("Cached 10 KeyPairs for RSA communication");
testCipher((RSAPrivateKey) _keyPairs[0]._pair.getPrivate());
// Store keys for blowfish communication
generateBlowFishKeys();
final Thread purge = new PurgeThread();
purge.setDaemon(true);
purge.start();
}
示例8: initialize
public void initialize(int keySize, SecureRandom random) {
// do not allow unreasonably small or large key sizes,
// probably user error
try {
RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
512, 64 * 1024);
} catch (InvalidKeyException e) {
throw new InvalidParameterException(e.getMessage());
}
this.keySize = keySize;
this.random = random;
this.publicExponent = RSAKeyGenParameterSpec.F4;
}
示例9: main
public static void main(String[] args) throws Exception {
RSAKeyGenParameterSpec rsaSpec =
new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
kpg.initialize(rsaSpec);
// test generateKeyPair
KeyPair kpair = kpg.generateKeyPair();
if (kpair == null) {
throw new Exception("no keypair generated");
}
}
示例10: generate
/**
* Generates an RSA key pair.
*
* @param bits The amount of bits
* @return The key pair
*/
public static KeyPair generate(int bits) throws Exception {
KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(bits,
RSAKeyGenParameterSpec.F4);
keygen.initialize(spec);
return keygen.generateKeyPair();
}
示例11: generateKeyPair
/**
* Generates a new 2014-bit RSA key pair.
* @return A new RSA key pair or null on error.
*/
public static KeyPair generateKeyPair() {
// Generate key pair for 1024-bit RSA encryption and decryption
try {
SecureRandom random = new SecureRandom();
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(spec, random);
return generator.genKeyPair();
} catch (Exception e) {
Log.e("HomeStuff", "RSA key pair error" + e);
return null;
}
}
示例12: LoginController
private LoginController() throws GeneralSecurityException
{
_log.info("Loading LoginController...");
_keyPairs = new ScrambledKeyPair[10];
KeyPairGenerator keygen = null;
keygen = KeyPairGenerator.getInstance("RSA");
RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
keygen.initialize(spec);
// generate the initial set of keys
for (int i = 0; i < 10; i++)
{
_keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
}
_log.info("Cached 10 KeyPairs for RSA communication");
testCipher((RSAPrivateKey) _keyPairs[0]._pair.getPrivate());
// Store keys for blowfish communication
generateBlowFishKeys();
Thread purge = new PurgeThread();
purge.setDaemon(true);
purge.start();
}
示例13: main
@Override
public void main(Provider p) throws Exception {
long start = System.currentTimeMillis();
provider = p;
data = new byte[2048];
// keypair generation is very slow, test only a few short keys
int[] keyLengths = {512, 512, 1024};
BigInteger[] pubExps = {null, RSAKeyGenParameterSpec.F4, null};
KeyPair[] keyPairs = new KeyPair[3];
RandomFactory.getRandom().nextBytes(data);
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", provider);
for (int i = 0; i < keyLengths.length; i++) {
int len = keyLengths[i];
BigInteger exp = pubExps[i];
System.out.println("Generating " + len + " bit keypair...");
if (exp == null) {
kpg.initialize(len);
} else {
kpg.initialize(new RSAKeyGenParameterSpec(len, exp));
}
KeyPair kp = kpg.generateKeyPair();
keyPairs[i] = kp;
RSAPublicKey publicKey = (RSAPublicKey)kp.getPublic();
System.out.println(publicKey);
RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey)kp.getPrivate();
if (publicKey.getModulus().equals(privateKey.getModulus()) == false) {
throw new Exception("Moduli do not match");
}
if (publicKey.getPublicExponent().equals(privateKey.getPublicExponent()) == false) {
throw new Exception("Exponents do not match");
}
int keyLen = publicKey.getModulus().bitLength();
if ((keyLen > len) || (keyLen < len - 1)) {
throw new Exception("Incorrect key length: " + keyLen);
}
if (exp != null) {
if (exp.equals(publicKey.getPublicExponent()) == false) {
throw new Exception("Incorrect exponent");
}
}
test(privateKey, publicKey);
}
testInvalidSignature(keyPairs[0], keyPairs[1]);
testInvalidSignature(keyPairs[0], keyPairs[2]);
long stop = System.currentTimeMillis();
System.out.println("All tests passed (" + (stop - start) + " ms).");
}