数据加密 [英] Data encrypting

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

问题描述

我被问到是否可以编写一个小应用程序来跟踪一些销售和购买信息。我接受这个项目作为学习项目,最终用户知道。该应用程序已通过第一次审核,现在我正在按要求进行一些小的更改。

I was asked if I could write a small application to track some sales and purchases info. I accepted this as project as a learning project and the end user is aware. The application has passed the first review and now I am making some small changes as requested.

其中一个愿望是数据安全性;应用程序通过序列化将数据存储在本地文件中,并将字节数组写入文件。用户担心这些数据仍然可以在存储文件中读取,并且只能使用应用程序读取数据
(需要登录)。

One of those wishes is data security; the application stores data in local files by serialization and writing the byte-array to file. The user is concerned that this data is still to read-able in the storage file and would like to only be able read the data using the application ( login required ).

问题是我在这里离开了我的联盟..是否有一个我可以参考的简单加密和解密课程或者我可以参考的免费课程库?

Problem is that I am out of my league here.. Is there a simple encrypting and decrypting class that I can reference or a free class library that I can reference?

所以我的问题是如何使用记事本打开时,我可以使保存的数据不可读。 

So my question is how can I make my saved data unreadable when using open with notepad. 

推荐答案

System.Security.Cryptography 有几种加密方法,并且有无数可用的例子。

System.Security.Cryptography has several encryption methods and there are countless examples available.

简单压缩将使输出不可读,这是一个例子:

Simple Compression will render the output unreadable, here's an example:

    Private Function DeflateCompress(ByVal raw() As Byte) As Byte()
        Using memory As MemoryStream = New MemoryStream()
            Using Deflate As DeflateStream = New DeflateStream(memory, CompressionMode.Compress, True)
                Deflate.Write(raw, 0, raw.Length)
            End Using
            Return memory.ToArray()
        End Using
    End Function

    Private Function DeflateDecompress(ByVal Compressed() As Byte) As Byte()
        Using stream As New DeflateStream(New MemoryStream(Compressed), CompressionMode.Decompress)
            Const size As Integer = 4096
            Dim buffer(size - 1) As Byte
            Using memory As New MemoryStream()
                Dim count As Integer = 0
                Do
                    count = stream.Read(buffer, 0, size)
                    If count > 0 Then
                        memory.Write(buffer, 0, count)
                    End If
                Loop While count > 0
                Return memory.ToArray()
            End Using
        End Using
    End Function

    Private Sub BtnCompDeComp_Click(sender As Object, e As EventArgs) Handles BtnCompDeComp.Click
        Dim TestPhrase As String = "I was asked if I could write a small application to track some sales and purchases info. " &
                                   "I accepted this as project as a learning project and the end user is aware. " &
                                   "The application has passed the first review and now I am making some small changes as requested."
        RichTextBox1.Text = "Original Text = " & vbNewLine & TestPhrase & vbNewLine & "Compressed as Byte Array = " & vbNewLine
        Dim Compressed() As Byte = DeflateCompress(Encoding.Default.GetBytes(TestPhrase))
        For Index = 0 To Compressed.Length - 1
            RichTextBox1.AppendText(Compressed(Index).ToString("X2") & " ")
        Next
        RichTextBox1.AppendText(vbNewLine)
        RichTextBox1.AppendText("As base64 String = " & vbNewLine & Convert.ToBase64String(Compressed) & vbNewLine)
        RichTextBox1.AppendText("Decompressed as Byte Array = " & vbNewLine)
        Dim Decompressed() As Byte = DeflateDecompress(Compressed)
        For Index = 0 To Compressed.Length - 1
            RichTextBox1.AppendText(Decompressed(Index).ToString("X2") & " ")
        Next
        RichTextBox1.AppendText(vbNewLine)
        RichTextBox1.AppendText("As base64 String = " & vbNewLine & Convert.ToBase64String(Decompressed) & vbNewLine)
        RichTextBox1.AppendText("As Text String = " & vbNewLine & Encoding.Default.GetString(Decompressed) & vbNewLine)

    End Sub

这需要以下Imports语句,至少

This requires the following Imports Statements, at the very least

Imports System.IO.Compression

Imports System.Text

Imports System.IO.Compression
Imports System.Text

输出 -  



这是不像完整的AES,RSA,DES加密那样安全,但更简单。熟练的,确定的坏人可能会识别出"标题字节"。并弄清楚它只是被压缩了。作为文本,这就是压缩数据的样子:

Output - 

This is not nearly as secure as Full AES, RSA, DES encryption, but is much simpler. A skilled, determined bad guy might recognize the "header bytes" and figure out that it is just compressed. As text, this is what the compressed data looks like:

MÍƒ0ƒWÑìÁ½ø.!IíЬ߄Ú"ž%}žÑÄ!~p®˜ò4ÓJü"!¥D
R5'ÔŒjx>	—È.OÊeaï"¦5OÝIB`©Ý·î:"P,?êh‘bIÓöÛ¦qI°×Ëi¢&Æ	¾þg؇™¸ó«XÕ¼ÂøV¶Û&å6òOœrŒˆ/êýJgLoãë¢wÀé

希望这是有用的。





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

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