I'm trying to encrypt data with BouncyCastle in VB so i take for reference this answer example code and have something like this:
Dim cerReader = New PemReader(File.OpenText("the\route\certificate.cer"))
Dim rsaPub = CType(cerReader.ReadObject(), Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters)
Dim encrypter = New OaepEncoding(New RsaEngine(), New Sha256Digest(), New Sha256Digest(), Nothing)
encrypter.Init(True, rsaPub)
Dim cipher = encrypter.ProcessBlock(data, 0, data.Length)
Return Convert.ToBase64String(cipher)
but in the line:
Dim rsaPub = CType(cerReader.ReadObject(), Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters)
gives me this error:
Cannot cast an object of type 'Org.BouncyCastle.X509.X509Certificate' to type 'Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters'.
and i can't found in the docs some example o make that cast or encrypt using .cer just .pem that i think is the same but doesn't work. Someone have a idea of what can I do?