pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

InvalidKeySpecException:algid 解析錯誤,不是序列

InvalidKeySpecException : algid parse error, not a sequence(InvalidKeySpecException:algid 解析錯誤,不是序列)
本文介紹了InvalidKeySpecException:algid 解析錯誤,不是序列的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在編寫一個程序,它接受來自控制臺的輸入 - zip 文件的名稱、要制作的 zip 文件的名稱,其中包含從第一個 zip 生成的(de/en)加密文件和一個包含公鑰.解密時出現異常:

線程main"中的異常 java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : algid parse error, not a sequence在 sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:217)在 java.security.KeyFactory.generatePrivate(KeyFactory.java:372)在 com.Main.makePrivateKey(Main.java:148)在 com.Main.decrypt(Main.java:40)在 com.Main.main(Main.java:182)引起:java.security.InvalidKeyException:IOException:algid解析錯誤,不是序列在 sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:351)在 sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:356)在 sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:91)在 sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:75)在 sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:316)在 sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:213)... 4 更多

不知道為什么,因為我在 makePrivateKey 方法中使用了正確的規范.我正在測試的鍵是(一個單獨的文件中的一個鍵的一行):

公鑰:

<預> <代碼> MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCE3pA746UfpC8sFk8ZJp0yupyJqj5jy6cjdxUYoP7mCm7c0mqQDeCcDNBYW2eSozCioPrH/9L + CDQEPLYakoem + jFnUKDH5 + PRU/0PJTJJF8Xh/ZT9eJlvsYBr1/qSfICf6RTs7kzwq9IuSZBw7/tfNEF9i0A8FVox6HOopXod1QIDAQAB

私鑰:

 <代碼> MIICXQIBAAKBgQCE3pA746UfpC8sFk8ZJp0yupyJqj5jy6cjdxUYoP7mCm7c0mqQDeCcDNBYW2eSozCioPrH/9L + CDQEPLYakoem + jFnUKDH5 + PRU/0PJTJJF8Xh/ZT9eJlvsYBr1/qSfICf6RTs7kzwq9IuSZBw7/tfNEF9i0A8FVox6HOopXod1QIDAQABAoGANOFrYBqK5lvu1koOswDWQZFZqcSSzh8IZyoGwGWa7S0r0EECXlDXmuPSq8e9IfRG8ALHrH + ZlrbnFOSgyVSWHfpj3aH + qknoSX5TW2rMQHih8865xuqheMQ + RTZ7 + BRDqNsYkzxB/Z8mqzpoJQSYf + H7nWxdDCgAJVYZzxl3DmUCQQD32iEjnwiwUjii8slcmvCEZl + z84DWNdvJOg6Z38sI4AvrfpKc1WAcDg1rNZCKrRgokh54wpLt08cpFcrD04c3AkEAiTzDmc0bdgfg5wj6xHFZpYlBwiGm/bjOR2PS57P0GNU5PsDllRbFqIuzArITutO5lvZZImzuYz7Lf + cQ73pxUwJBAOdEwmdaneDo17A0m2 + TO3/nhqWDMVSwLMU3RyiNigZeCMFU + bkd4PBMrHi9IoJDwacZsRU9eZwxYEUV8H2Jg0ECQEEkOqRSm2pXKwX/WSjNtQPCNxhy6NUeV6vDUmTxIjh3XYjP/ynZeVEbnoj1BjB0N2/U11Jj6nPpZqb7gyppMEkCQQCoGdVYDipU+hMMnvxa0zOIyQc/a+HE0lESqn+2ZPafYi9Z1RldRMvUXhP8U7s+OuhRwprdw2ivvOFrnWyz9lL2

該程序的代碼如下.歡迎任何幫助:)

包com;導入 java.io.BufferedReader;導入java.io.File;導入 java.io.FileInputStream;導入 java.io.FileOutputStream;導入 java.io.FileReader;導入 java.io.IOException;導入 java.io.InputStream;導入 java.io.OutputStream;導入 java.security.GeneralSecurityException;導入 java.security.KeyFactory;導入 java.security.PrivateKey;導入 java.security.PublicKey;導入 java.security.Security;導入 java.security.spec.PKCS8EncodedKeySpec;導入 java.security.spec.X509EncodedKeySpec;導入 java.util.Base64;導入 java.util.Enumeration;導入 java.util.Scanner;導入 java.util.zip.ZipEntry;導入 java.util.zip.ZipFile;導入 java.util.zip.ZipOutputStream;導入 javax.crypto.Cipher;公共類主要{公共最終靜態 int BUFFER_SIZE = 117;公共靜態無效解密(字符串 originalZipFileName,字符串 newZipFileName,字符串 privateKeyFileName)拋出異常 {字節[] 緩沖區 = 新字節[BUFFER_SIZE];ZipFile originalZipFile = new ZipFile(originalZipFileName);ZipOutputStream newZipFile = new ZipOutputStream(new FileOutputStream(newZipFileName));枚舉zipEntries = originalZipFile.entries();字符串 privateKey = getKeyString(privateKeyFileName);PrivateKey key = makePrivateKey(privateKey);密碼密碼 = Cipher.getInstance("RSA");cipher.init(Cipher.DECRYPT_MODE, key);文件 file = new File("temp.txt");而(zipEntries.hasMoreElements()){ZipEntry 條目 = zipEntries.nextElement();ZipEntry 副本 = 新 ZipEntry(entry.getName());newZipFile.putNextEntry(復制);整數讀取;InputStream inputEntry = originalZipFile.getInputStream(entry);OutputStream outputFile = new FileOutputStream(file);而((讀取= inputEntry.read(緩沖區))!= -1){outputFile.write(cipher.doFinal(buffer), 0, read);}InputStream inputTempFile = new FileInputStream(file);而((讀取= inputTempFile.read(緩沖區))!= -1){newZipFile.write(緩沖區,0,讀取);}newZipFile.closeEntry();inputEntry.close();inputTempFile.close();輸出文件.close();文件.刪除();}newZipFile.close();}公共靜態無效加密(字符串 originalZipFileName,字符串 newZipFileName,字符串 publicKeyFileName)拋出異常 {字節[] 緩沖區 = 新字節[BUFFER_SIZE];ZipFile originalZipFile = new ZipFile(originalZipFileName);ZipOutputStream newZipFile = new ZipOutputStream(new FileOutputStream(newZipFileName));枚舉zipEntries = originalZipFile.entries();字符串 publicKey = getKeyString(publicKeyFileName);PublicKey 密鑰 = makePublicKey(publicKey);密碼密碼 = Cipher.getInstance("RSA");cipher.init(Cipher.ENCRYPT_MODE,密鑰);文件 file = new File("temp.txt");而(zipEntries.hasMoreElements()){ZipEntry 條目 = zipEntries.nextElement();ZipEntry 副本 = 新 ZipEntry(entry.getName());newZipFile.putNextEntry(復制);整數讀取;InputStream inputEntry = originalZipFile.getInputStream(entry);OutputStream outputFile = new FileOutputStream(file);而((讀取= inputEntry.read(緩沖區))!= -1){outputFile.write(cipher.doFinal(buffer), 0, read);}InputStream inputTempFile = new FileInputStream(file);而((讀取= inputTempFile.read(緩沖區))!= -1){newZipFile.write(緩沖區,0,讀取);}newZipFile.closeEntry();inputEntry.close();inputTempFile.close();輸出文件.close();文件.刪除();}newZipFile.close();}公共靜態字符串 getKeyString(字符串文件名){字符串鍵 = 新字符串();嘗試 {BufferedReader buf = new BufferedReader(new FileReader(fileName));鍵 = buf.readLine();} 捕捉(IOException e){e.printStackTrace();}返回 key.trim();}公共靜態 PublicKey makePublicKey(字符串存儲)拋出 GeneralSecurityException {byte[] data = Base64.getDecoder().decode(stored);X509EncodedKeySpec 規范 = 新 X509EncodedKeySpec(data);KeyFactory 事實 = KeyFactory.getInstance("RSA");返回 fact.generatePublic(spec);}公共靜態 PrivateKey makePrivateKey(字符串存儲)拋出 GeneralSecurityException {byte[] data = Base64.getDecoder().decode(stored);PKCS8EncodedKeySpec 規范 = 新 PKCS8EncodedKeySpec(data);KeyFactory 事實 = KeyFactory.getInstance("RSA");返回 fact.generatePrivate(spec);}公共靜態 void main(String[] args) 拋出異常 {掃描儀掃描 = 新的掃描儀(System.in);System.out.println("輸入操作類型:");字符串線 = scan.nextLine();如果(line.equals(加密")){System.out.println("輸入原始ZIP文件名:");字符串 originalZipFileName = scan.nextLine();System.out.println("請輸入新 ZIP 文件的名稱:");字符串 newZipFileName = scan.nextLine();System.out.println("請輸入包含公鑰的文件名:");字符串 publicKeyFileName = scan.nextLine();加密(originalZipFileName,newZipFileName,publicKeyFileName);}如果(line.equals(解密")){System.out.println("輸入原始ZIP文件名:");字符串 originalZipFileName = scan.nextLine();System.out.println("請輸入新 ZIP 文件的名稱:");字符串 newZipFileName = scan.nextLine();System.out.println("請輸入包含私鑰的文件名:");String privateKeyFileName = scan.nextLine();解密(originalZipFileName,newZipFileName,privateKeyFileName);}}}

解決方案

您的私鑰不是 PKCS#8 格式.您必須向其添加關鍵算法信息以使其成為 PKCS#8,然后它才能工作.

您可能應該更改生成密鑰的方式,以使它們采用 PKCS#8 格式.但由于我對此一無所知,我將只展示如何使用 BouncyCastle 庫在您的應用程序中更新密鑰:

@Test公共 void testKey() 拋出異常 {串privKeyStr =MIICXQIBAAKBgQCE3pA746UfpC8sFk8ZJp0yupyJqj5jy6cjdxUYoP7mCm7c0mqQDeCcDNBYW2eSozCioPrH/9L + CDQEPLYakoem + jFnUKDH5 + PRU/0PJTJJF8Xh/ZT9eJlvsYBr1/qSfICf6RTs7kzwq9IuSZBw7/tfNEF9i0A8FVox6HOopXod1QIDAQABAoGANOFrYBqK5lvu1koOswDWQZFZqcSSzh8IZyoGwGWa7S0r0EECXlDXmuPSq8e9IfRG8ALHrH + ZlrbnFOSgyVSWHfpj3aH + qknoSX5TW2rMQHih8865xuqheMQ + RTZ7 + BRDqNsYkzxB/Z8mqzpoJQSYf + H7nWxdDCgAJVYZzxl3DmUCQQD32iEjnwiwUjii8slcmvCEZl + z84DWNdvJOg6Z38sI4AvrfpKc1WAcDg1rNZCKrRgokh54wpLt08cpFcrD04c3AkEAiTzDmc0bdgfg5wj6xHFZpYlBwiGm/bjOR2PS57P0GNU5PsDllRbFqIuzArITutO5lvZZImzuYz7Lf + cQ73pxUwJBAOdEwmdaneDo17A0m2 + TO3/nhqWDMVSwLMU3RyiNigZeCMFU + bkd4PBMrHi9IoJDwacZsRU9eZwxYEUV8H2Jg0ECQEEkOqRSm2pXKwX/WSjNtQPCNxhy6NUeV6vDUmTxIjh3XYjP/ynZeVEbnoj1BjB0N2/U11Jj6nPpZqb7gyppMEkCQQCoGdVYDipU+hMMnvxa0zOIyQc/a+HE0lESqn+2ZPafYi9Z1RldRMvUXhP8U7s+OuhRwprdw2ivvOFrnWyz9lL2";byte[] data = Base64.getDecoder().decode(privKeyStr);/* 添加 PKCS#8 格式 */ASN1EncodableVector v = new ASN1EncodableVector();v.add(new ASN1Integer(0));ASN1EncodableVector v2 = new ASN1EncodableVector();v2.add(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.rsaEncryption.getId()));v2.add(DERNull.INSTANCE);v.add(新 DERSequence(v2));v.add(新DEROCtetString(數據));ASN1Sequence seq = new DERSequence(v);byte[] privKey = seq.getEncoded("DER");PKCS8EncodedKeySpec 規范 = 新 PKCS8EncodedKeySpec(privKey);KeyFactory 事實 = KeyFactory.getInstance("RSA");PrivateKey key = fact.generatePrivate(spec);Assert.assertNotNull("生成私鑰失敗", key);}

I'm writing a program which takes as input from the console - the name of a zip file, name of a zip file to be made containig the (de/en)crypted files generated from the first zip and a file containing the public key. I get the exception when decrypting:

Exception in thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : algid parse error, not a sequence
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:217)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:372)
at com.Main.makePrivateKey(Main.java:148)
at com.Main.decrypt(Main.java:40)
at com.Main.main(Main.java:182)
Caused by: java.security.InvalidKeyException: IOException : algid parse error, not a sequence
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:351)
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:356)
at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:91)
at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:75)
at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:316)
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:213)
... 4 more

Can't figure out why because the I use the rigth spec in the makePrivateKey method. The keys I'm testing with are(one line for a key each in a separate file):

Public key:

MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCE3pA746UfpC8sFk8ZJp0yupyJqj5jy6cjdxUYoP7mCm7c0mqQDeCcDNBYW2eSozCioPrH/9L+CDQEPLYakoem+jFnUKDH5+pru/0PJTJJF8Xh/ZT9eJlvsYBr1/qSfICf6RTs7kzwq9IuSZBw7/tfNEF9i0A8FVox6HOopXod1QIDAQAB

Private key:

MIICXQIBAAKBgQCE3pA746UfpC8sFk8ZJp0yupyJqj5jy6cjdxUYoP7mCm7c0mqQDeCcDNBYW2eSozCioPrH/9L+CDQEPLYakoem+jFnUKDH5+pru/0PJTJJF8Xh/ZT9eJlvsYBr1/qSfICf6RTs7kzwq9IuSZBw7/tfNEF9i0A8FVox6HOopXod1QIDAQABAoGANOFrYBqK5lvu1koOswDWQZFZqcSSzh8IZyoGwGWa7S0r0EECXlDXmuPSq8e9IfRG8ALHrH+ZlrbnFOSgyVSWHfpj3aH+qknoSX5TW2rMQHih8865xuqheMQ+RTZ7+BRDqNsYkzxB/Z8mqzpoJQSYf+H7nWxdDCgAJVYZzxl3DmUCQQD32iEjnwiwUjii8slcmvCEZl+z84DWNdvJOg6Z38sI4AvrfpKc1WAcDg1rNZCKrRgokh54wpLt08cpFcrD04c3AkEAiTzDmc0bdgfg5wj6xHFZpYlBwiGm/bjOR2PS57P0GNU5PsDllRbFqIuzArITutO5lvZZImzuYz7Lf+cQ73pxUwJBAOdEwmdaneDo17A0m2+to3/nhqWDMVSwLMU3RyiNigZeCMFU+bkd4PBMrHi9IoJDwacZsRU9eZwxYEUV8H2Jg0ECQEEkOqRSm2pXKwX/WSjNtQPCNxhy6NUeV6vDUmTxIjh3XYjP/ynZeVEbnoj1BjB0N2/U11Jj6nPpZqb7gyppMEkCQQCoGdVYDipU+hMMnvxa0zOIyQc/a+HE0lESqn+2ZPafYi9Z1RldRMvUXhP8U7s+OuhRwprdw2ivvOFrnWyz9lL2

The code for the program is bellow . Any help is wellcomed :)

package com;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Security;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

import javax.crypto.Cipher;

public class Main {

public final static int BUFFER_SIZE = 117;

public static void decrypt(String originalZipFileName, String newZipFileName, String privateKeyFileName) throws Exception {
    byte[] buffer = new byte[BUFFER_SIZE];  

    ZipFile originalZipFile = new ZipFile(originalZipFileName); 
    ZipOutputStream newZipFile = new ZipOutputStream(new FileOutputStream(newZipFileName));

    Enumeration<? extends ZipEntry> zipEntries = originalZipFile.entries();

    String privateKey = getKeyString(privateKeyFileName);
    PrivateKey key = makePrivateKey(privateKey);

    Cipher cipher = Cipher.getInstance("RSA");

    cipher.init(Cipher.DECRYPT_MODE, key);
    File file = new File("temp.txt");

    while(zipEntries.hasMoreElements()){

        ZipEntry entry = zipEntries.nextElement();          

        ZipEntry copy = new ZipEntry(entry.getName());      
        newZipFile.putNextEntry(copy);

        int read;           
        InputStream inputEntry = originalZipFile.getInputStream(entry);
        OutputStream outputFile = new FileOutputStream(file);

        while((read = inputEntry.read(buffer)) != -1){              
            outputFile.write(cipher.doFinal(buffer), 0, read);
        }

        InputStream inputTempFile = new FileInputStream(file);

        while((read = inputTempFile.read(buffer)) != -1){
            newZipFile.write(buffer, 0, read);
        }

        newZipFile.closeEntry();
        inputEntry.close();
        inputTempFile.close();
        outputFile.close();
        file.delete();
    }
    newZipFile.close();
}

public static void encrypt(String originalZipFileName, String newZipFileName, String publicKeyFileName) throws Exception{

    byte[] buffer = new byte[BUFFER_SIZE];  

    ZipFile originalZipFile = new ZipFile(originalZipFileName); 
    ZipOutputStream newZipFile = new ZipOutputStream(new FileOutputStream(newZipFileName));

    Enumeration<? extends ZipEntry> zipEntries = originalZipFile.entries();

    String publicKey = getKeyString(publicKeyFileName);
    PublicKey key = makePublicKey(publicKey);

    Cipher cipher = Cipher.getInstance("RSA");

    cipher.init(Cipher.ENCRYPT_MODE, key);
    File file = new File("temp.txt");

    while(zipEntries.hasMoreElements()){

        ZipEntry entry = zipEntries.nextElement();          

        ZipEntry copy = new ZipEntry(entry.getName());      
        newZipFile.putNextEntry(copy);

        int read;           
        InputStream inputEntry = originalZipFile.getInputStream(entry);
        OutputStream outputFile = new FileOutputStream(file);

        while((read = inputEntry.read(buffer)) != -1){              
            outputFile.write(cipher.doFinal(buffer), 0, read);
        }

        InputStream inputTempFile = new FileInputStream(file);

        while((read = inputTempFile.read(buffer)) != -1){
            newZipFile.write(buffer, 0, read);
        }

        newZipFile.closeEntry();
        inputEntry.close();
        inputTempFile.close();
        outputFile.close();
        file.delete();
    }
    newZipFile.close();
}   

public static String getKeyString(String fileName){

    String key = new String();
    try {
        BufferedReader buf = new BufferedReader(new FileReader(fileName));
        key = buf.readLine();       
    } catch ( IOException e) {
        e.printStackTrace();
    }   

    return key.trim();
}

public static PublicKey makePublicKey(String stored) throws GeneralSecurityException {
    byte[] data = Base64.getDecoder().decode(stored);
    X509EncodedKeySpec spec = new  X509EncodedKeySpec(data);
    KeyFactory fact = KeyFactory.getInstance("RSA");
    return fact.generatePublic(spec);
}

public static PrivateKey makePrivateKey(String stored) throws GeneralSecurityException {
    byte[] data = Base64.getDecoder().decode(stored);
    PKCS8EncodedKeySpec spec = new  PKCS8EncodedKeySpec(data);
    KeyFactory fact = KeyFactory.getInstance("RSA");
    return fact.generatePrivate(spec);
}

public static void main(String[] args) throws Exception {

    Scanner scan = new Scanner(System.in);

    System.out.println("Enter type of operation:");
    String line = scan.nextLine();

    if(line.equals("encrypt")){
        System.out.println("Enter name of original ZIP file:");
        String originalZipFileName = scan.nextLine();

        System.out.println("Enter name of new ZIP file:");
        String newZipFileName = scan.nextLine();

        System.out.println("Enter name of file containg public key:");
        String publicKeyFileName = scan.nextLine();

        encrypt(originalZipFileName, newZipFileName, publicKeyFileName);        
    }
    if(line.equals("decrypt")){
        System.out.println("Enter name of original ZIP file:");
        String originalZipFileName = scan.nextLine();

        System.out.println("Enter name of new ZIP file:");
        String newZipFileName = scan.nextLine();

        System.out.println("Enter name of file containg private key:");
        String privateKeyFileName = scan.nextLine();

        decrypt(originalZipFileName, newZipFileName, privateKeyFileName);       
    }       

}

}

解決方案

Your private key is not in PKCS#8 format. You have to add key algorithm information to it to make it PKCS#8 and then it will work.

Probably you should alter the way you generate keys to have them in PKCS#8 format. But since I know nothing on that I will just show how to update key to it in your application using BouncyCastle library:

@Test
public void testKey() throws Exception {
    String privKeyStr = "MIICXQIBAAKBgQCE3pA746UfpC8sFk8ZJp0yupyJqj5jy6cjdxUYoP7mCm7c0mqQDeCcDNBYW2eSozCioPrH/9L+CDQEPLYakoem+jFnUKDH5+pru/0PJTJJF8Xh/ZT9eJlvsYBr1/qSfICf6RTs7kzwq9IuSZBw7/tfNEF9i0A8FVox6HOopXod1QIDAQABAoGANOFrYBqK5lvu1koOswDWQZFZqcSSzh8IZyoGwGWa7S0r0EECXlDXmuPSq8e9IfRG8ALHrH+ZlrbnFOSgyVSWHfpj3aH+qknoSX5TW2rMQHih8865xuqheMQ+RTZ7+BRDqNsYkzxB/Z8mqzpoJQSYf+H7nWxdDCgAJVYZzxl3DmUCQQD32iEjnwiwUjii8slcmvCEZl+z84DWNdvJOg6Z38sI4AvrfpKc1WAcDg1rNZCKrRgokh54wpLt08cpFcrD04c3AkEAiTzDmc0bdgfg5wj6xHFZpYlBwiGm/bjOR2PS57P0GNU5PsDllRbFqIuzArITutO5lvZZImzuYz7Lf+cQ73pxUwJBAOdEwmdaneDo17A0m2+to3/nhqWDMVSwLMU3RyiNigZeCMFU+bkd4PBMrHi9IoJDwacZsRU9eZwxYEUV8H2Jg0ECQEEkOqRSm2pXKwX/WSjNtQPCNxhy6NUeV6vDUmTxIjh3XYjP/ynZeVEbnoj1BjB0N2/U11Jj6nPpZqb7gyppMEkCQQCoGdVYDipU+hMMnvxa0zOIyQc/a+HE0lESqn+2ZPafYi9Z1RldRMvUXhP8U7s+OuhRwprdw2ivvOFrnWyz9lL2";
    byte[] data = Base64.getDecoder().decode(privKeyStr);

    /* Add PKCS#8 formatting */
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new ASN1Integer(0));
    ASN1EncodableVector v2 = new ASN1EncodableVector();
    v2.add(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.rsaEncryption.getId()));
    v2.add(DERNull.INSTANCE);
    v.add(new DERSequence(v2));
    v.add(new DEROctetString(data));
    ASN1Sequence seq = new DERSequence(v);
    byte[] privKey = seq.getEncoded("DER");

    PKCS8EncodedKeySpec spec = new  PKCS8EncodedKeySpec(privKey);
    KeyFactory fact = KeyFactory.getInstance("RSA");
    PrivateKey key = fact.generatePrivate(spec);
    Assert.assertNotNull("Failed to generate the private key", key);
}

這篇關于InvalidKeySpecException:algid 解析錯誤,不是序列的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Java Remove Duplicates from an Array?(Java從數組中刪除重復項?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復調用失敗來自服務器的意外響應:在 Android 工作室中未經授權)
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 选矿设备-新型重选设备-金属矿尾矿重选-青州冠诚重工机械有限公司 | 河南不锈钢水箱_地埋水箱_镀锌板水箱_消防水箱厂家-河南联固供水设备有限公司 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 不锈钢丸厂家,铝丸,铸钢丸-淄博智源铸造材料有限公司 | 南京雕塑制作厂家-不锈钢雕塑制作-玻璃钢雕塑制作-先登雕塑厂 | 塑料熔指仪-塑料熔融指数仪-熔体流动速率试验机-广东宏拓仪器科技有限公司 | 齿轮减速马达一体式_蜗轮蜗杆减速机配电机-德国BOSERL齿轮减速电动机生产厂家 | 无缝钢管-聊城无缝钢管-小口径无缝钢管-大口径无缝钢管 - 聊城宽达钢管有限公司 | 商用绞肉机-熟肉切片机-冻肉切丁机-猪肉开条机 - 广州市正盈机械设备有限公司 | 杭州成人高考_浙江省成人高考网上报名| 全自动贴标机-套标机-工业热风机-不干胶贴标机-上海厚冉机械 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 中宏网-今日新闻-财经新闻 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | IPO咨询公司-IPO上市服务-细分市场研究-龙马咨询 | 天津电机维修|水泵维修-天津晟佳机电设备有限公司 | 硅胶制品-硅橡胶制品-东莞硅胶制品厂家-广东帝博科技有限公司 | 熔体泵|换网器|熔体齿轮泵|熔体计量泵厂家-郑州巴特熔体泵有限公司 | 上海办公室装修,写字楼装修—启鸣装饰设计工程有限公司 | 七维官网-水性工业漆_轨道交通涂料_钢结构漆 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 餐饮小吃技术培训-火锅串串香培训「何小胖培训」_成都点石成金[官网] | 盘式曝气器-微孔曝气器-管式曝气器-曝气盘-斜管填料 | 郑州市前程水处理有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 防爆鼓风机-全风-宏丰鼓风机-上海梁瑾机电设备有限公司 | 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 橡胶粉碎机_橡胶磨粉机_轮胎粉碎机_轮胎磨粉机-河南鼎聚重工机械制造有限公司 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 海尔生物医疗四川代理商,海尔低温冰箱四川销售-成都壹科医疗器械有限公司 | 老房子翻新装修,旧房墙面翻新,房屋防水补漏,厨房卫生间改造,室内装潢装修公司 - 一修房屋快修官网 | 盐水蒸发器,水洗盐设备,冷凝结晶切片机,转鼓切片机,絮凝剂加药系统-无锡瑞司恩机械有限公司 | 周易算网-八字测算网 - 周易算网-宝宝起名取名测名字周易八字测算网 | 温州富欧金属封头-不锈钢封头厂家| 阿里巴巴诚信通温州、台州、宁波、嘉兴授权渠道商-浙江联欣科技提供阿里会员办理 | 北京网站建设-企业网站建设-建站公司-做网站-北京良言多米网络公司 | 河南中专学校|职高|技校招生-河南中职中专网| 汕头市盛大文化传播有限公司,www.11400.cc | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 陕西华春网络科技股份有限公司|