本文整理汇总了Java中java.security.spec.RSAKeyGenParameterSpec类的典型用法代码示例。如果您正苦于以下问题:Java RSAKeyGenParameterSpec类的具体用法?Java RSAKeyGenParameterSpec怎么用?Java RSAKeyGenParameterSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RSAKeyGenParameterSpec类属于java.security.spec包,在下文中一共展示了RSAKeyGenParameterSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LoginController
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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: initialize
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
public void initialize(
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidAlgorithmParameterException
{
if (!(params instanceof RSAKeyGenParameterSpec))
{
throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
}
RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;
param = new RSAKeyGenerationParameters(
rsaParams.getPublicExponent(),
random, rsaParams.getKeysize(), defaultTests);
engine.init(param);
}
示例3: generateRSAKeypair
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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();
}
}
示例4: createKeysM
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
static void createKeysM(String alias, boolean requireAuth) {
try {
KeyPairGenerator keyPairGenerator =
KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(alias,
KeyProperties.PURPOSE_ENCRYPT
| KeyProperties.PURPOSE_DECRYPT).setAlgorithmParameterSpec(
new RSAKeyGenParameterSpec(1024, F4))
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384,
KeyProperties.DIGEST_SHA512)
// Only permit the private key to be used if the user authenticated
// within the last five minutes.
.setUserAuthenticationRequired(requireAuth)
.build());
KeyPair keyPair = keyPairGenerator.generateKeyPair();
Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());
} catch (NoSuchProviderException | NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
throw new RuntimeException(e);
}
}
示例5: initRSAKeys
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
/**
* Inits the RSA keys.
*/
private void initRSAKeys()
{
try
{
final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(new RSAKeyGenParameterSpec(512, RSAKeyGenParameterSpec.F4));
_keyPairs = new KeyPair[KEYS_SIZE];
for (int i = 0; i < KEYS_SIZE; i++)
{
_keyPairs[i] = keyGen.genKeyPair();
}
}
catch (Exception e)
{
LOGGER.severe(GameServerTable.class.getSimpleName() + ": Error loading RSA keys for Game Server communication!");
}
}
示例6: main
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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.");
}
}
示例7: createKeysM
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private static void createKeysM(String alias, boolean requireAuth)
throws NoSuchProviderException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException {
KeyPairGenerator keyPairGenerator =
KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(alias,
KeyProperties.PURPOSE_ENCRYPT
| KeyProperties.PURPOSE_DECRYPT).setAlgorithmParameterSpec(
new RSAKeyGenParameterSpec(1024, F4))
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384,
KeyProperties.DIGEST_SHA512)
// Only permit the private key to be used if the user authenticated
// within the last five minutes.
.setUserAuthenticationRequired(requireAuth)
.build());
KeyPair keyPair = keyPairGenerator.generateKeyPair();
Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());
}
示例8: initialize
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
throws InvalidAlgorithmParameterException {
if (!(params instanceof RSAKeyGenParameterSpec)) {
throw new InvalidAlgorithmParameterException("Only RSAKeyGenParameterSpec supported");
}
RSAKeyGenParameterSpec spec = (RSAKeyGenParameterSpec) params;
final BigInteger publicExponent = spec.getPublicExponent();
if (publicExponent != null) {
this.publicExponent = publicExponent.toByteArray();
}
this.modulusBits = spec.getKeysize();
}
示例9: initialize
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
throws InvalidAlgorithmParameterException
{
HashMap attributes = new HashMap();
if (params != null)
{
if (! (params instanceof RSAKeyGenParameterSpec))
throw new InvalidAlgorithmParameterException("params");
attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
}
if (random != null)
attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);
attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
Integer.valueOf(Registry.ASN1_ENCODING_ID));
adaptee.setup(attributes);
}
示例10: CertRASession
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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;
}
示例11: test
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
@Test
public void test() throws Exception {
// install BouncyCastle provider
Security.addProvider(new BouncyCastleProvider());
// generate a keypair
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "BC");
RSAKeyGenParameterSpec params = new RSAKeyGenParameterSpec(STRENGTH, PUBLIC_EXP);
gen.initialize(params, new SecureRandom());
KeyPair keyPair = gen.generateKeyPair();
FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration();
// serialize
byte[] serialized = fst.asByteArray(keyPair);
// deserialize --> crash
KeyPair deserialized = (KeyPair) fst.asObject(serialized);
}
示例12: initialize
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
public void initialize(
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidAlgorithmParameterException
{
if (!(params instanceof RSAKeyGenParameterSpec))
{
throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
}
RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;
param = new RSAKeyGenerationParameters(
rsaParams.getPublicExponent(),
random, rsaParams.getKeysize(), defaultTests);
engine.init(param);
}
示例13: genKeys
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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();
}
}
示例14: loadRSAKeys
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
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();
}
}
示例15: setup
import java.security.spec.RSAKeyGenParameterSpec; //导入依赖的package包/类
/**
* Setup the test.
*/
@BeforeClass
public static void setup() throws Exception {
Provider bc = new BouncyCastleProvider();
Security.addProvider(bc);
final byte[] preimage = "Hello World!".getBytes(Charset.defaultCharset());
final byte[] prefix = "Ying ".getBytes(Charset.defaultCharset());
final byte[] message = "Yang".getBytes(Charset.defaultCharset());
//final byte[] prefixedMessage = "Ying Yang".getBytes(Charset.defaultCharset());
final MessageDigest sha256Digest = MessageDigest.getInstance("SHA-256");
final MessageDigest sha512Digest = MessageDigest.getInstance("SHA-512");
//final byte[] fingerprint = sha256Digest.digest(preimage);
final KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
rsaKpg.initialize(new RSAKeyGenParameterSpec(2048, new BigInteger("65537")));
KeyPair rsaKeyPair = rsaKpg.generateKeyPair();
Signature rsaSigner = Signature.getInstance("SHA256withRSA/PSS");
rsaSigner.initSign(rsaKeyPair.getPrivate());
rsaSigner.update(message);
net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
KeyPair edDsaKeyPair = edDsaKpg.generateKeyPair();
Signature edDsaSigner = new EdDSAEngine(sha512Digest);
edDsaSigner.initSign(edDsaKeyPair.getPrivate());
edDsaSigner.update(prefix);
edDsaSigner.update(message);
preimageCondition = new PreimageSha256Condition(preimage);
rsaCondition = new RsaSha256Condition((RSAPublicKey) rsaKeyPair.getPublic());
ed25519Condition = new Ed25519Sha256Condition((EdDSAPublicKey) edDsaKeyPair.getPublic());
prefixSha256Condition
= new PrefixSha256Condition(prefix, 1000, ed25519Condition);
thresholdCondition = new ThresholdSha256Condition(
2,
Lists.newArrayList(preimageCondition, rsaCondition, prefixSha256Condition)
);
byte[] rsaSignature = rsaSigner.sign();
byte[] edDsaSignature = edDsaSigner.sign();
preimageFulfillment = new PreimageSha256Fulfillment(preimage);
rsaFulfillment = new RsaSha256Fulfillment((RSAPublicKey) rsaKeyPair.getPublic(), rsaSignature);
ed25519Fulfillment =
new Ed25519Sha256Fulfillment((EdDSAPublicKey) edDsaKeyPair.getPublic(), edDsaSignature);
prefixSha256Fulfillment =
new PrefixSha256Fulfillment(prefix, 1000, ed25519Fulfillment);
thresholdFulfillment =
new ThresholdSha256Fulfillment(
Lists.newArrayList(rsaCondition),
Lists.newArrayList(preimageFulfillment, prefixSha256Fulfillment)
);
}