Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

473
Visualizações
Decoding the keys from RSACryptoServiceProvider

I am trying to extract the private keys from an RSACryptoServiceProvider object using .ExportRSAPrivateKey(). As per MSDN, it exports a "byte array containing the PKCS#1 RSAPrivateKey representation of this key", which representation is defined in Appendix A of RFC8017. So based on that, I assume that it should be ASN1-encoded and try to use an AsnReader class:

using (var rsa = new RSACryptoServiceProvider(1024))
{
    var priv = rsa.ExportRSAPrivateKey();
    var asnr = new AsnReader(priv, AsnEncodingRules.DER);
    var N = asnr.ReadInteger();
}

However, this code fails on .ReadInteger() with exception: "The provided data is tagged with 'Universal' class value '16', but it should have been 'Universal' class value '2'."

What am I doing wrong?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It's because RSAPublicKey is a SEQUENCE ...

So you have to read a sequence and then, the integer ...

I guess you are using Microsoft AsnReader class

So, the code could be something like:

var publicKey = asnr.ReadSequence()
var N = publickKey.ReadInteger()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda