`
shappy1978
  • 浏览: 698409 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

"algid parse error, not a sequence" on initialize private key of RSA

    博客分类:
  • J2EE
 
阅读更多

You get this error because you are reading a PKCS#8 key file, but your file has a PKCS#1 format (PKCS#1 has the BEGIN RSA PRIVATE KEY header while PKCS#8 has the BEGIN PRIVATE KEY header).

In order to read both PKCS#1 and PKCS#8 PEM files, I use the source code of Apache JMeter's org.apache.jmeter.protocol.oauth.sampler.PrivateKeyReader:

PrivateKey pk = (new PrivateKeyReader("/path/to/myfile.der")).getPrivateKey();

 

Alternately you can conver your mykey.pem to DER format and use your existing code. Following is the openssl command to do that

//generate PKCS#1 key 
openssl genrsa -out mykey.pem 1024
//generate public key
openssl rsa -in mykey.pem -pubout > mykey.pub
//Convert to PKCS#8
openssl pkcs8 -topk8 -inform PEM -outform DER -in mykey.pem -out mykey.der -nocrypt
分享到:
评论

相关推荐

    NTE Error Codes

    8. **NTE_BAD_ALGID** (80090008):无效的算法标识符。指定的加密算法不受支持或不被识别。 9. **NTE_BAD_FLAGS** (80090009):无效的标志。使用的标志参数可能与加密操作的要求不符。 10. **NTE_BAD_TYPE** ...

    vb6.0 MD5 vb md5 加密

    Private Declare Function CryptCreateHash Lib "advapi32.dll" (ByVal hProv As Long, ByVal algID As Long, ByVal hKey As Long, ByVal dwFlags As Long, ByRef phHash As Long) As Long Private Declare Function...

    cad图纸加密C++实现

    // Set these two to reflect '*' key stroke pResult[resultLen] = keyCode; // but keep the real keycode. resultLen++; } if (keyCode == 8 && resultLen) resultLen--; } return FALSE; } ``` ##### 2...

    VB6_SHA256示例.zip

    Private Declare Function CryptCreateHash Lib "advapi32.dll" (ByVal hProv As Long, ByVal Algid As Long, ByVal hKey As Long, ByVal dwFlags As Long, ByRef phHash As Long) As Long Private Declare Function...

    VB6.0 MD5加密算法 支持中文(调用Window API计算)

    Private Declare Function CryptCreateHash Lib "advapi32.dll" (ByVal hProv As Long, ByVal Algid As Long, ByVal hKey As Long, ByVal dwFlags As Long, ByRef phHash As Long) As Long Private Declare Function...

    MD5_MD5vb6_

    Private Declare Function CryptCreateHash Lib "advapi32.dll" (ByVal hProv As Long, ByVal Algid As Long, ByVal hKey As Long, ByVal dwFlags As Long, ByRef phHash As Long) As Long Private Declare Function...

    VB6获取文件哈希值源代码

    Private Declare Function CreateHash Lib "advapi32.dll" (ByVal algId As Long, ByVal reserved As Long, ByVal hProv As Long) As Long Private Declare Function GetHash Lib "advapi32.dll" (ByVal hHash As ...

    通用单步单求解积分算法:结构动力学问题的直接线性或非线性显式或隐式时间积分-matlab开发

    % GSSSS(ExcData,Fint_K_C,m,AlgID,rinf,varargin) % 一般线性或非线性显式或隐式直接时间SDOF 或 MDOF 的二阶微分方程的积分百分比% 动态系统% % 描述%通用单步单求解(GSSSS)系列算法X.Zhou & KKTamma (2004) ...

    frramework编写的C#加密通用类

    然后,我们定义了一个内部构造函数`internal EncryptTransformer(EncryptionAlgorithm algId)`,用于设置当前使用的加密算法。这个构造函数接收一个`EncryptionAlgorithm`枚举值作为参数,用来指定加密算法类型。 ...

Global site tag (gtag.js) - Google Analytics