Java Key Create getKeys()

Here you can find the source of getKeys()

Description

get Keys

License

Apache License

Declaration

public static HashMap<String, Object> getKeys() throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

import java.util.HashMap;

public class Main {

    public static HashMap<String, Object> getKeys() throws NoSuchAlgorithmException {
        HashMap<String, Object> map = new HashMap<String, Object>();
        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
        keyPairGen.initialize(1024);/*  w w  w. java  2  s  .  c  o m*/
        KeyPair keyPair = keyPairGen.generateKeyPair();
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
        RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
        map.put("public", publicKey);
        map.put("private", privateKey);
        return map;
    }
}

Related

  1. getKeyPair()
  2. getKeyPair()
  3. getKeyPair()
  4. getKeyPair(KeyStore keyStore, String alias, String password)
  5. getKeyPairGenerator(final String algorithm)
  6. getKeySize(final Key key)
  7. getKeySize(PrivateKey key)
  8. getKeyStore()
  9. getKeyStore()