将 PKCS#1 编码格式的 Base64 字符串转换为 PKCS#8 编码格式的 Base64 字符串,转换的是 ECC 密钥对, 帮我编写一套 java 代码
时间: 2024-03-01 19:54:15 浏览: 58
好的,以下是示例代码:
```java
import java.io.IOException;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
public class KeyConversion {
public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
// PKCS#1 encoded ECC key pair in Base64 format
String pkcs1PrivateKeyBase64 = "MIHcAgEBBEIBuZ3nUqE9VzXhct1Xg6PqA4K4jZ2kCp1FhL6StQDvOPU60eYi8z9YbE7g0SgKJqG/8iKv8W8kz7CDAGgBwYFK4EEACOhgYkDgYYABABM8f8BdN6V9RzDgYLfC2o+1Z6R4ivKJL6BkFz6VJ9L1q5gJ/5evm6Xu7Mf2rGQ3LW5EAG4yWwqK9E8j6b4mBzRd+9R8t5dCwhmLzg3jQtt/5Zt6pRgFyF/DlYGDvWxtiJfy9tV2NQ2Rf+ZM1zOx1uQr7zEzZ1D5j7TfQw==";
String pkcs1PublicKeyBase64 = "MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQATPH/AXTelfUcw4GC3wtpPtWekeIryiS+gZBc+lSfS9auYCf+Xr5ul7uzH9qxkNy1uRABuMlsKivRPI
阅读全文