code: public static String[] generateKeyPair(int keySize) { 
      	
          // KeyPairGenerator类用于生成公钥和私钥对，基于RSA算法生成对象  
          KeyPairGenerator keyPairGen = null;  
          try {  
              keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);  
          } catch (NoSuchAlgorithmException e) {  
              // TODO Auto-generated catch block  
              e.printStackTrace();  
          }  
          // 初始化密钥对生成器，密钥大小为96-1024位  
          keyPairGen.initialize(keySize,new SecureRandom());  
          // 生成一个密钥对，保存在keyPair中  
          KeyPair keyPair = keyPairGen.generateKeyPair();  
          // 得到私钥  
          RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();  
          // 得到公钥  
          RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();  
          try {  
              // 得到公钥字符串  
              String publicKeyString = Base64.encodeToString(publicKey.getEncoded(),true);  
              // 得到私钥字符串  
              String privateKeyString = Base64.encodeToString(privateKey.getEncoded(),true);  
             
              return new String[]{publicKeyString,privateKeyString};
          } catch (Exception e) {  
              throw new RuntimeException(e);
          }  
      }
docs: 生成RSA密匙对
  @param keySize
  @return [pubkey,prikey]