| | |
| | | // 2048 bits 的 RSA 密钥对,最大加密明文大小 |
| | | private static final int MAX_ENCRYPT_BLOCK = MAX_DECRYPT_BLOCK - RESERVE_BYTES; |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | Map<String, Object> map = initKey(1024); |
| | | |
| | | String privateKeyStr = getPrivateKeyStr(map); |
| | | log.info("-----私钥={}", privateKeyStr); |
| | | |
| | | String publicKeyStr = getPublicKeyStr(map); |
| | | log.info("-----公钥={}", publicKeyStr); |
| | | } |
| | | |
| | | // 生成密钥对 |
| | | public static Map<String, Object> initKey(int keysize) throws Exception { |
| | | KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); |