Java Key Pair Create generateKeyPair(int keySize, String fileChavePublica, String fileChavePrivada)

Here you can find the source of generateKeyPair(int keySize, String fileChavePublica, String fileChavePrivada)

Description

generate Key Pair

License

Open Source License

Declaration

public static void generateKeyPair(int keySize,
            String fileChavePublica, String fileChavePrivada)
            throws NoSuchAlgorithmException, FileNotFoundException,
            IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;

import java.security.KeyPair;
import java.security.KeyPairGenerator;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

public class Main {
    public static void generateKeyPair(int keySize,
            String fileChavePublica, String fileChavePrivada)
            throws NoSuchAlgorithmException, FileNotFoundException,
            IOException {//from ww  w .  jav a 2  s . c  o  m
        KeyPairGenerator pairgen = KeyPairGenerator.getInstance("RSA");
        SecureRandom random = new SecureRandom();
        pairgen.initialize(keySize, random);
        KeyPair keyPair = pairgen.generateKeyPair();
        ObjectOutputStream out = new ObjectOutputStream(
                new FileOutputStream(fileChavePublica));
        out.writeObject(keyPair.getPublic());
        out.close();
        out = new ObjectOutputStream(new FileOutputStream(fileChavePrivada));
        out.writeObject(keyPair.getPrivate());
        out.close();
    }
}

Related

  1. generateKeyPair(int keySize)
  2. generateKeyPair(int keySize)
  3. generateKeyPair(int keySize)
  4. generateKeyPair(int keySize)
  5. generateKeyPair(int keysize)
  6. generateKeyPair(int keySizeInBits, String algo)
  7. generateKeyPair(int len)
  8. generateKeyPair(int size)
  9. generateKeyPair(String algo)