解密加密文本VB NET [英] Decrypt an encrypted text VB NET

查看:100
本文介绍了解密加密文本VB NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家下午好。我从REST服务获得响应,并将其放在字符串变量中。



我现在需要隔离整个文本的某些部分以便操作他们分开;例如,我需要解密XML,记录数字文档的标记日期,以及其他部分信息。



我知道我可以使用文本函数来提取我需要的信息,但我认为应该是更好,更有效的方法来完成这项工作。



是否可以在数据集中注册字符串变量的信息然后从那里取出?或者任何其他建议??。



我尝试过:



与此同时,为了不停止,我将尝试使用VB Net文本函数,但我对此感到不舒服。

解决方案

您的问题是关于解密,还是从字符串中提取内容的更好方法?我将按照你的帖子中的问题并尝试回答它们,

Quote:

我需要解密XML

你有没有密码或解密邮件的密钥?如果没有,则问题在此结束,因为没有合理的方法从加密消息中获取数据和值。



如果你这样做,那么检查一下使用了什么加密方法 - 让极客们高兴,使用了什么算法的加密。然后,您可以使用加密助手的VB.NET变体来解密消息。



在Microsoft Documentations上查看示例,在Visual Basic中加密和解密字符串Microsoft Docs [ ^ ]



Quote:

是否可以在数据集中注册字符串变量的信息,然后从那里取出?或任何其他建议??。

如果该数据类似于键值对,那么是的,您可以将其存储为您认为有用的格式 - HashSet 也许是为了更好的表现?但是这一部分都将在你解密文本之后出现。而且,如果来自REST API的数据是结构化的,例如JSON,那么这将是可能的,然后您可以立即将其解析为对象并使用它。在这部分问题中尝试更具体一点。


根据解决方案1的注释中的代码,你有一个 JSON [ ^ ]字符串包含 Base64 [ ^ ]编码的XML文件。



你需要一个JSON解析库 - 我用 JSON.NET [ ^ ]。



然后,您需要一个类来表示JSON对象。它并不完全清楚,因为一些属性是 null 或空数组。但是这样的事情应该让你开始:

  Class  InfoRecord 
公开 属性 uuid As Guid
公开 属性 fechaCancelacion As DateTime
< span class =code-keyword>公共 属性 estatus 作为 整数
公共 属性 descripcion 作为 字符串
公共 属性 selloCFD 作为 字符串
公开 属性 tipoTimbre 作为 字符串
公共 属性 rfcEmisor As 字符串
结束 Class

ErrorRecord
公共 属性 codigo 作为 整数
公开 属性 descripcion 作为 字符串
公共 属性 html 作为 字符串
结束

包装器
公共 属性 [< span class =code-keyword> error ] As ErrorRecord
公开 属性 uuid 作为 Guid
公共 属性 timbresRestantes 作为 字符串
公共 属性 xml 作为 字符串
公共 属性 info 作为列表( InfoRecord)

公开 ReadOnly 属性 XmlDocument 作为 XDocument
获取
如果 字符串 .IsNullOrEmpty(xml)然后 返回 没什么

Dim xmlBytes 作为 字节()= Convert.FromBase64String(xml)
Dim encodedXml As String = System .Text.Encoding。默认 .GetString(xmlBytes)

返回 XDocument.Parse(decodingXml)
结束 获取
结束 属性
结束



添加对JSON.NET的NuGet引用,并导入 Newtonsoft .Json 命名空间。然后,您可以将字符串转换为 Wrapper 类的实例,并访问XML文档:

  Dim  data  As  Wrapper = JsonConvert.DeserializeObject( Of  Wraper)(yourStringVariable)
Dim xml As XDocument = data.XmlDocument
如果 xml IsNot Nothing 然后
... >这里的XML ...
结束 如果


Good Afternoon Everybody. I am getting a response from a REST service, and I put it in a string variable.

I need now to isolate certains parts of the entire text in order to manipulate them separately; for example, I need to decrypt the XML, take the stamping date of a digital document, and other portions of information included.

I know I can use text functions to extract the information I need, but I think it should be better and more efficient ways to do this job.

Is it possible to register the information of the string variable in a dataset and then take it from there ??. Or any other suggestion ??.

What I have tried:

In the meantime, just for not be stopped, I'm going to try to use VB Net text functions, but I don´t feel comfortable with this.

解决方案

Your question is about decryption, or better way to extract content from a string? I will follow the questions in your post and try to answer them,

Quote:

I need to decrypt the XML

Do you have the password or the key to decrypt the message? If not, then the question ends here because there is no sensible way to get the data and values back from the encrypted message.

If you do, then check what method of encryption was used — to keep geeks happy, what algorithm of encryption was used. You can then use the VB.NET variants of cryptographic helpers to decrypt the message.

Take a look at samples here at Microsoft Documentations, Encrypting and Decrypting Strings in Visual Basic | Microsoft Docs[^]

Quote:

Is it possible to register the information of the string variable in a dataset and then take it from there ??. Or any other suggestion ??.

If that data is like a key-value pair, then yes, you can store it in a format that you find useful — HashSet perhaps for better performance? But this part will all come after you have decrypted the text. And also, this will be possible if the data from REST API is structured, like JSON, then you can parse it into an object right away and use it. Try being a bit more specific in this part of your question.


Based on the code in the comments to solution 1, you have a JSON[^] string containing a Base64[^] encoded XML file.

You'll want a JSON parsing library - I use JSON.NET[^].

You'll then want a class to represent the JSON object. It's not entirely clear, since some of the properties are null or empty arrays. But something like this should get you started:

Class InfoRecord
    Public Property uuid As Guid
    Public Property fechaCancelacion As DateTime
    Public Property estatus As Integer
    Public Property descripcion As String
    Public Property selloCFD As String
    Public Property tipoTimbre As String
    Public Property rfcEmisor As String
End Class

Class ErrorRecord
    Public Property codigo As Integer
    Public Property descripcion As String
    Public Property html As String
End Class

Class Wrapper
    Public Property [error] As ErrorRecord
    Public Property uuid As Guid
    Public Property timbresRestantes As String
    Public Property xml As String
    Public Property info As List(Of InfoRecord)
    
    Public ReadOnly Property XmlDocument As XDocument
        Get
            If String.IsNullOrEmpty(xml) Then Return Nothing
            
            Dim xmlBytes As Byte() = Convert.FromBase64String(xml)
            Dim decodedXml As String = System.Text.Encoding.Default.GetString(xmlBytes)
            
            Return XDocument.Parse(decodedXml)
        End Get
    End Property
End Class


Add a NuGet reference to JSON.NET, and import the Newtonsoft.Json namespace. You can then convert your string to an instance of the Wrapper class, and access the XML document:

Dim data As Wrapper = JsonConvert.DeserializeObject(Of Wraper)(yourStringVariable)
Dim xml As XDocument = data.XmlDocument
If xml IsNot Nothing Then
    ... Do something with the XML here ...
End If


这篇关于解密加密文本VB NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆