You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

加载加密OpenSSH密钥时提示密码错误的技术求助

问题:使用Chilkat.SshKey加载ECDSA 521-bit OpenSSH密钥失败

我正尝试在应用中使用Chilkat.SshKey读取ECDSA 521-bit OpenSSH密钥,用于新SSH服务器的身份验证。查阅了官方文档和示例,但加载密钥时始终报错,错误日志如下:

ChilkatLog:
  FromOpenSshPrivateKey(32ms):
    DllDate: May 25 2017
    ChilkatVersion: 9.5.0.68
    UnlockPrefix: <mycode>
    Architecture: Little Endian; 32-bit
    Language: .NET 4.5
    VerboseLogging: 1
    fromOpenSshPrivateKey(32ms):
      loadPem2(32ms):
        loadPem(16ms):
          itemType: OPENSSH PRIVATE KEY
          addPemItem(16ms):
            itemType: OPENSSH PRIVATE KEY
            loadAnyDerPw(16ms):
              DecodeToAsn:
                premature end of BER encoding (F2)
                length: 115
                numBytesLeft: 108
              --DecodeToAsn
              loadAnyAsn:
                Invalid ASN.1 for public/private key
              --loadAnyAsn
              der_to_xml:
                ASN data length exceeds remaining number of bytes available.
                tag: 19
                idClass: 1
                bConstructed: 1
                headerLen: 2
                dataLen: 115
                inlen: 108
                Abort ASN.1 processing...
                recursiveDepth: 2
                Abort ASN.1 processing...
                recursiveDepth: 1
              --der_to_xml
              der_xml: <?xml version="1.0" encoding="utf-8" ?>
<application tag="15" constructed="1">
    <application tag="5" constructed="1" />
</application>

            --loadAnyDerPw
          --addPemItem
          No more -----BEGIN's found.
        --loadPem
      --loadPem2
      Check the password, it may be incorrect.
    --fromOpenSshPrivateKey
    Failed.
  --FromOpenSshPrivateKey
--ChilkatLog

我的VB代码如下:

Dim MyKey As New SshKey With {.Password = "<private_key_password>", .VerboseLogging = True}
Dim SSHKeyString As String = MyKey.LoadText("<path_to_private_key>")

If Not MyKey.FromOpenSshPrivateKey(SSHKeyString) Then
    Throw New Exception("Failed to load the private key." & vbCrLf & vbCrLf & MyKey.LastErrorText)
Else
    MessageBox.Show("Private key loaded successfully")
End If

本地验证情况

  • 最初从服务器共享读取文件时,ssh-keygen命令报错权限问题;将文件复制到本地并调整权限后,该命令能正确返回密钥信息:
    ecdsa-sha2-nistp521 <KEY CONTENTS HERE> ssh@mydomain.com
    
  • 测试错误密码时,命令会明确提示:
    Load key "<path_to_private_key>": incorrect passphrase supplied to decrypt private key
    

已尝试的排查步骤

  • 怀疑密码含标点符号导致问题,创建带简单密码testpass的同参数密钥,仍得到相同的密码错误提示;
  • 创建无密码密钥后,错误变为提示未设置Password属性,即使移除该属性或设为空值也无效。

请问我遗漏了什么?


内容的提问来源于stack exchange,提问作者G_Hosa_Phat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 01:14:50