org.spongycastle.crypto.generators.RSAKeyPairGenerator Java Examples

The following examples show how to use org.spongycastle.crypto.generators.RSAKeyPairGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PgpUtils.java    From proofmode with GNU General Public License v3.0 6 votes vote down vote up
public final static PGPKeyRingGenerator generateKeyRingGenerator (String keyId, char[] pass) throws PGPException{
    RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
    kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), new SecureRandom(), 4096, 12));
    PGPKeyPair rsakp_sign = new BcPGPKeyPair(PGPPublicKey.RSA_GENERAL, kpg.generateKeyPair(), new Date());
    PGPKeyPair rsakp_enc = new BcPGPKeyPair(PGPPublicKey.RSA_GENERAL, kpg.generateKeyPair(), new Date());
    PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();
    signhashgen.setKeyFlags(false, KeyFlags.SIGN_DATA|KeyFlags.CERTIFY_OTHER|KeyFlags.SHARED);
    signhashgen.setPreferredSymmetricAlgorithms(false, new int[]{SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, SymmetricKeyAlgorithmTags.AES_128});
    signhashgen.setPreferredHashAlgorithms(false, new int[]{HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512, HashAlgorithmTags.SHA224});
    signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);
    PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
    enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
    PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
    PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA256);
    PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha256Calc, 0xc0)).build(pass);
    PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator (PGPSignature.POSITIVE_CERTIFICATION, rsakp_sign,
            keyId, sha1Calc, signhashgen.generate(), null, new BcPGPContentSignerBuilder(rsakp_sign.getPublicKey().getAlgorithm(),
            HashAlgorithmTags.SHA1), pske);
    keyRingGen.addSubKey(rsakp_enc, enchashgen.generate(), null);
    return keyRingGen;
}
 
Example #2
Source File: Cryptograph.java    From SightRemote with GNU General Public License v3.0 5 votes vote down vote up
public static KeyPair generateRSAKey() {
    RSAKeyPairGenerator generator = new RSAKeyPairGenerator();
    generator.init(new RSAKeyGenerationParameters(BigInteger.valueOf(65537), new SecureRandom(),2048, 8));
    AsymmetricCipherKeyPair ackp = generator.generateKeyPair();
    KeyPair keyPair = new KeyPair();
    keyPair.privateKey = (RSAPrivateCrtKeyParameters) ackp.getPrivate();
    keyPair.publicKey = (RSAKeyParameters) ackp.getPublic();
    return keyPair;
}
 
Example #3
Source File: Cryptograph.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public static KeyPair generateRSAKey() {
    RSAKeyPairGenerator generator = new RSAKeyPairGenerator();
    generator.init(new RSAKeyGenerationParameters(BigInteger.valueOf(65537), new SecureRandom(), 2048, 8));
    AsymmetricCipherKeyPair ackp = generator.generateKeyPair();
    KeyPair keyPair = new KeyPair();
    keyPair.privateKey = (RSAPrivateCrtKeyParameters) ackp.getPrivate();
    keyPair.publicKey = (RSAKeyParameters) ackp.getPublic();
    return keyPair;
}