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

InvalidKeySpecException:algid 解析錯(cuò)誤,不是序列

InvalidKeySpecException : algid parse error, not a sequence(InvalidKeySpecException:algid 解析錯(cuò)誤,不是序列)
本文介紹了InvalidKeySpecException:algid 解析錯(cuò)誤,不是序列的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

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

線程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解析錯(cuò)誤,不是序列在 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 更多

不知道為什么,因?yàn)槲以?makePrivateKey 方法中使用了正確的規(guī)范.我正在測(cè)試的鍵是(一個(gè)單獨(dú)的文件中的一個(gè)鍵的一行):

公鑰:

<預(yù)> <代碼> 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

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

包c(diǎn)om;導(dǎo)入 java.io.BufferedReader;導(dǎo)入java.io.File;導(dǎo)入 java.io.FileInputStream;導(dǎo)入 java.io.FileOutputStream;導(dǎo)入 java.io.FileReader;導(dǎo)入 java.io.IOException;導(dǎo)入 java.io.InputStream;導(dǎo)入 java.io.OutputStream;導(dǎo)入 java.security.GeneralSecurityException;導(dǎo)入 java.security.KeyFactory;導(dǎo)入 java.security.PrivateKey;導(dǎo)入 java.security.PublicKey;導(dǎo)入 java.security.Security;導(dǎo)入 java.security.spec.PKCS8EncodedKeySpec;導(dǎo)入 java.security.spec.X509EncodedKeySpec;導(dǎo)入 java.util.Base64;導(dǎo)入 java.util.Enumeration;導(dǎo)入 java.util.Scanner;導(dǎo)入 java.util.zip.ZipEntry;導(dǎo)入 java.util.zip.ZipFile;導(dǎo)入 java.util.zip.ZipOutputStream;導(dǎo)入 javax.crypto.Cipher;公共類主要{公共最終靜態(tài) int BUFFER_SIZE = 117;公共靜態(tài)無(wú)效解密(字符串 originalZipFileName,字符串 newZipFileName,字符串 privateKeyFileName)拋出異常 {字節(jié)[] 緩沖區(qū) = 新字節(jié)[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(復(fù)制);整數(shù)讀取;InputStream inputEntry = originalZipFile.getInputStream(entry);OutputStream outputFile = new FileOutputStream(file);而((讀取= inputEntry.read(緩沖區(qū)))!= -1){outputFile.write(cipher.doFinal(buffer), 0, read);}InputStream inputTempFile = new FileInputStream(file);而((讀取= inputTempFile.read(緩沖區(qū)))!= -1){newZipFile.write(緩沖區(qū),0,讀取);}newZipFile.closeEntry();inputEntry.close();inputTempFile.close();輸出文件.close();文件.刪除();}newZipFile.close();}公共靜態(tài)無(wú)效加密(字符串 originalZipFileName,字符串 newZipFileName,字符串 publicKeyFileName)拋出異常 {字節(jié)[] 緩沖區(qū) = 新字節(jié)[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(復(fù)制);整數(shù)讀??;InputStream inputEntry = originalZipFile.getInputStream(entry);OutputStream outputFile = new FileOutputStream(file);而((讀取= inputEntry.read(緩沖區(qū)))!= -1){outputFile.write(cipher.doFinal(buffer), 0, read);}InputStream inputTempFile = new FileInputStream(file);而((讀取= inputTempFile.read(緩沖區(qū)))!= -1){newZipFile.write(緩沖區(qū),0,讀取);}newZipFile.closeEntry();inputEntry.close();inputTempFile.close();輸出文件.close();文件.刪除();}newZipFile.close();}公共靜態(tài)字符串 getKeyString(字符串文件名){字符串鍵 = 新字符串();嘗試 {BufferedReader buf = new BufferedReader(new FileReader(fileName));鍵 = buf.readLine();} 捕捉(IOException e){e.printStackTrace();}返回 key.trim();}公共靜態(tài) PublicKey makePublicKey(字符串存儲(chǔ))拋出 GeneralSecurityException {byte[] data = Base64.getDecoder().decode(stored);X509EncodedKeySpec 規(guī)范 = 新 X509EncodedKeySpec(data);KeyFactory 事實(shí) = KeyFactory.getInstance("RSA");返回 fact.generatePublic(spec);}公共靜態(tài) PrivateKey makePrivateKey(字符串存儲(chǔ))拋出 GeneralSecurityException {byte[] data = Base64.getDecoder().decode(stored);PKCS8EncodedKeySpec 規(guī)范 = 新 PKCS8EncodedKeySpec(data);KeyFactory 事實(shí) = KeyFactory.getInstance("RSA");返回 fact.generatePrivate(spec);}公共靜態(tài) void main(String[] args) 拋出異常 {掃描儀掃描 = 新的掃描儀(System.in);System.out.println("輸入操作類型:");字符串線 = scan.nextLine();如果(line.equals(加密")){System.out.println("輸入原始ZIP文件名:");字符串 originalZipFileName = scan.nextLine();System.out.println("請(qǐng)輸入新 ZIP 文件的名稱:");字符串 newZipFileName = scan.nextLine();System.out.println("請(qǐng)輸入包含公鑰的文件名:");字符串 publicKeyFileName = scan.nextLine();加密(originalZipFileName,newZipFileName,publicKeyFileName);}如果(line.equals(解密")){System.out.println("輸入原始ZIP文件名:");字符串 originalZipFileName = scan.nextLine();System.out.println("請(qǐng)輸入新 ZIP 文件的名稱:");字符串 newZipFileName = scan.nextLine();System.out.println("請(qǐng)輸入包含私鑰的文件名:");String privateKeyFileName = scan.nextLine();解密(originalZipFileName,newZipFileName,privateKeyFileName);}}}

解決方案

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

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

@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(數(shù)據(jù)));ASN1Sequence seq = new DERSequence(v);byte[] privKey = seq.getEncoded("DER");PKCS8EncodedKeySpec 規(guī)范 = 新 PKCS8EncodedKeySpec(privKey);KeyFactory 事實(shí) = 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);
}

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

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

相關(guān)文檔推薦

Java Remove Duplicates from an Array?(Java從數(shù)組中刪除重復(fù)項(xiàng)?)
How to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修復(fù)調(diào)用失敗來(lái)自服務(wù)器的意外響應(yīng):在 Android 工作室中未經(jīng)授權(quán))
AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES Error: Given final block not properly padded(AES 錯(cuò)誤:給定的最終塊未正確填充)
Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 檢測(cè)不正確的密鑰)
AES-256-CBC in Java(Java 中的 AES-256-CBC)
主站蜘蛛池模板: 北京晚会活动策划|北京节目录制后期剪辑|北京演播厅出租租赁-北京龙视星光文化传媒有限公司 | 纯水电导率测定仪-万用气体检测仪-低钠测定仪-米沃奇科技(北京)有限公司www.milwaukeeinst.cn 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 手术室净化装修-手术室净化工程公司-华锐手术室净化厂家 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛调查出轨取证公司_青岛婚外情取证-青岛探真调查事务所 | 氨水-液氨-工业氨水-氨水生产厂家-辽宁顺程化工 | 电机保护器-电动机综合保护器-上海硕吉电器有限公司 | 螺杆式冷水机-低温冷水机厂家-冷冻机-风冷式-水冷式冷水机-上海祝松机械有限公司 | 等离子空气净化器_医用空气消毒机_空气净化消毒机_中央家用新风系统厂家_利安达官网 | 北京公寓出租网-北京酒店式公寓出租平台| 短信通106短信接口验证码接口群发平台_国际短信接口验证码接口群发平台-速度网络有限公司 | 鄂泉泵业官网|(杭州、上海、全国畅销)大流量防汛排涝泵-LW立式排污泵 | 脑钠肽-白介素4|白介素8试剂盒-研域(上海)化学试剂有限公司 | 物和码官网,物和码,免费一物一码数字化营销SaaS平台 | 重庆监控_电子围栏设备安装公司_门禁停车场管理系统-劲浪科技公司 | 818手游网_提供当下热门APP手游_最新手机游戏下载 | 胜为光纤光缆_光纤跳线_单模尾纤_光纤收发器_ODF光纤配线架厂家直销_北京睿创胜为科技有限公司 - 北京睿创胜为科技有限公司 | 123悬赏网_发布悬赏任务_广告任务平台 | 建筑工程资质合作-工程资质加盟分公司-建筑资质加盟 | 起好名字_取个好名字_好名网免费取好名在线打分 | 蓝莓施肥机,智能施肥机,自动施肥机,水肥一体化项目,水肥一体机厂家,小型施肥机,圣大节水,滴灌施工方案,山东圣大节水科技有限公司官网17864474793 | 便携式表面粗糙度仪-彩屏硬度计-分体式粗糙度仪-北京凯达科仪科技有限公司 | 冰雕-冰雪世界-大型冰雕展制作公司-赛北冰雕官网 | 大连海岛旅游网>>大连旅游,大连海岛游,旅游景点攻略,海岛旅游官网 | 郑州墨香品牌设计公司|品牌全案VI设计公司 | 合肥礼品公司-合肥礼品定制-商务礼品定制公司-安徽柏榽商贸有限公司 | 东莞螺丝|东莞螺丝厂|东莞不锈钢螺丝|东莞组合螺丝|东莞精密螺丝厂家-东莞利浩五金专业紧固件厂家 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 薄壁轴承-等截面薄壁轴承生产厂家-洛阳薄壁精密轴承有限公司 | 定时排水阀/排气阀-仪表三通旋塞阀-直角式脉冲电磁阀-永嘉良科阀门有限公司 | 除甲醛公司-甲醛检测-广西雅居环境科技有限公司 | 升降机-高空作业车租赁-蜘蛛车-曲臂式伸缩臂剪叉式液压升降平台-脚手架-【普雷斯特公司厂家】 | 除尘器布袋骨架,除尘器滤袋,除尘器骨架,电磁脉冲阀膜片,卸灰阀,螺旋输送机-泊头市天润环保机械设备有限公司 | 钢制暖气片散热器_天津钢制暖气片_卡麦罗散热器厂家 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 防火卷帘门价格-聊城一维工贸特级防火卷帘门厂家▲ | 济南律师,济南法律咨询,山东法律顾问-山东沃德律师事务所 | 广州小程序开发_APP开发公司_分销商城系统定制_小跑科技 | 矿用履带式平板车|探水钻机|气动架柱式钻机|架柱式液压回转钻机|履带式钻机-启睿探水钻机厂家 | 一氧化氮泄露报警器,二甲苯浓度超标报警器-郑州汇瑞埔电子技术有限公司 | 开业庆典_舞龙舞狮_乔迁奠基仪式_开工仪式-神挚龙狮鼓乐文化传媒 |