| | |
| | | package com.lf.server.helper; |
| | | |
| | | import org.apache.tomcat.util.codec.binary.Base64; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | |
| | | import javax.crypto.Cipher; |
| | |
| | | */ |
| | | private static String publicKey; |
| | | |
| | | /** |
| | | * 密钥算法 |
| | | */ |
| | | private static final String KEY_ALGORITHM = "RSA"; |
| | | |
| | | /** |
| | | * RSA密钥长度:1024 或 2048 |
| | | */ |
| | | private static final int DEFAULT_RSA_KEY_SIZE = 1024; |
| | | |
| | | /** |
| | | * 日志 |
| | | */ |
| | | private final static Log log = LogFactory.getLog(RsaHelper.class); |
| | | |
| | | /** |
| | | * 生成公私钥 |
| | |
| | | // 得到私钥字符串 |
| | | String pri = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded())); |
| | | result.put("privateKey", pri); |
| | | } catch (GeneralSecurityException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return result; |