在linux上生成RSA公钥,转换为base64,并导入VB.NET

时间:2013-03-08 03:25:07

标签: vb.net rsa

我想将字符串硬编码为VB.NET程序,该程序包含我在Linux计算机上生成的RSA公钥的base64字符串表示。

在linux框中:

  • 我使用ssh-keygen生成密钥对
  • 我使用PHP将.ssh / id_rsa.pub转换为base64,使用base64_encode()

在VB代码中,我将上面生成的输出硬编码为字符串变量:

Dim publicKey As String = "QUFBQUIzTnphQzF5YzJFQUFBQUJJd0FBQVFFQTRrNHNPOFhyajhJUkM4WGhEMVJQYlhJbUROTnVwdEpvUEtYNzNhcHc1M0NFUGE3VVNRY0U2SXhyNENWM2FhVXBtR1Fsb1I4akNLVkNoUnhzOUVnT3JQcVNGMTFjL3ZPNzluMXdkU1VWZjhreC9uY1NiV25UUXBtb1paNlN5ZUM3ekhMbWh1Z0o5OWdsVjB3bXBhTXpPeitHa0JBeFBPYlV0MzFYalMxMlBzM0ZUZFBla2s5T0ptMFJxc1plM3krbHU2UURZbDEyejJyTU9lbFhJS2IxSUZ1SnF6SThqL2Y4Q3V2dGxCSmxhelRBWlkyekF1WTZWMXU4c2JnUmE2MTBxMzM3dUdMODErbytCUkRzS0dwN0xBRmRwM1R2ekE3MDZPeFVSSEF0YmRZOVkzaXFISFFzQ3ZQWXBqcVQ0MHVlZ1RHY05jd2JCdjZxa2xlckk2K25Ndz09"

Dim myRsa As New RSACryptoServiceProvider()
myRsa.ImportCspBlob(Convert.FromBase64String(publicKey))

我收到关于“糟糕的提供商版本”的运行时异常

1 个答案:

答案 0 :(得分:1)

以下是我如何转换它(使用phpseclib, a pure PHP RSA implementation):

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();

$rsa->loadKey(base64_decode('QUFBQUIzTnphQzF5YzJFQUFBQUJJd0FBQVFFQTRrNHNPOFhyajhJUkM4WGhEMVJQYlhJbUROTnVwdEpvUEtYNzNhcHc1M0NFUGE3VVNRY0U2SXhyNENWM2FhVXBtR1Fsb1I4akNLVkNoUnhzOUVnT3JQcVNGMTFjL3ZPNzluMXdkU1VWZjhreC9uY1NiV25UUXBtb1paNlN5ZUM3ekhMbWh1Z0o5OWdsVjB3bXBhTXpPeitHa0JBeFBPYlV0MzFYalMxMlBzM0ZUZFBla2s5T0ptMFJxc1plM3krbHU2UURZbDEyejJyTU9lbFhJS2IxSUZ1SnF6SThqL2Y4Q3V2dGxCSmxhelRBWlkyekF1WTZWMXU4c2JnUmE2MTBxMzM3dUdMODErbytCUkRzS0dwN0xBRmRwM1R2ekE3MDZPeFVSSEF0YmRZOVkzaXFISFFzQ3ZQWXBqcVQ0MHVlZ1RHY05jd2JCdjZxa2xlckk2K25Ndz09'));
$rsa->setPublicKey();

$publickey = $rsa->getPublicKey(CRYPT_RSA_PUBLIC_FORMAT_XML);

echo $publickey;