| | |
| | | package com.ruoyi.shop.util; |
| | | |
| | | import cn.hutool.core.codec.Base64; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import java.io.BufferedInputStream; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.security.KeyFactory; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.PrivateKey; |
| | | import java.security.cert.*; |
| | | import java.security.spec.InvalidKeySpecException; |
| | | import java.security.spec.PKCS8EncodedKeySpec; |
| | | |
| | | |
| | | /** |
| | | * @date 2020-03-18 11:25 |
| | | * @description 证书相关 |
| | |
| | | * @param priKeyPath 商户私钥证书路径 |
| | | * @return |
| | | */ |
| | | public static String getPrivateKey(String priKeyPath) throws Exception { |
| | | /*public static String getPrivateKey(String priKeyPath) throws Exception { |
| | | String originalKey = FileUtil.readUtf8String(priKeyPath); |
| | | String privateKey = originalKey |
| | | .replace("-----BEGIN PRIVATE KEY-----", "") |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | *//** |
| | | * 从字符串中加载私钥 |
| | | * @param privateKeyStr 私钥 |
| | | * @return |
| | | */ |
| | | *//* |
| | | public static PrivateKey loadPrivateKey(String privateKeyStr) throws Exception { |
| | | try { |
| | | byte[] buffer = Base64.decode(privateKeyStr); |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | *//** |
| | | * 获取证书 |
| | | * @param fileName 证书文件路径 (required) |
| | | * @return |
| | | */ |
| | | *//* |
| | | public static X509Certificate getCertificate(String fileName) throws IOException { |
| | | InputStream fis = new FileInputStream(fileName); |
| | | try (BufferedInputStream bis = new BufferedInputStream(fis)) { |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | *//** |
| | | * 获取证书 |
| | | * @param inputStream 证书文件 |
| | | * @return |
| | | */ |
| | | *//* |
| | | public static X509Certificate getCertificate(InputStream inputStream) { |
| | | try { |
| | | CertificateFactory cf = CertificateFactory.getInstance("X509"); |
| | |
| | | } catch (CertificateException e) { |
| | | throw new RuntimeException("无效的证书", e); |
| | | } |
| | | } |
| | | }*/ |
| | | } |