在asp.net中使用DES进行文件解密 [英] file decryption using DES in asp.net

查看:70
本文介绍了在asp.net中使用DES进行文件解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的第一篇文章。我试图在ASP.Net中用C#使用DES算法进行文件加密和解密。我已成功加密文件并上传。下载时,加密文件将可用。现在,我需要通过上传控件选择文件来解密文件。任何人都可以帮助我吗?



加密代码如下:

Hi,
This is my first post. I am trying to do file encryption and decryption using DES algorithm in ASP.Net with C#. I have successfully encrypted the file and uploaded it. When I download, the encrypted file will be available. Now, I need to decrypt the file by selecting the file through upload control. Can any one please help me?

The encryption code is below:

filename = Path.GetFileName(FileUpload1.PostedFile.FileName);

        System.IO.Stream myStream;
        Int32 fileLen;
        StringBuilder displayString = new StringBuilder();
        fileLen = FileUpload1.PostedFile.ContentLength;

        Byte[] Input = new Byte[fileLen];

        // Initialize the stream to read the uploaded file.
        myStream = FileUpload1.FileContent;

        // Read the file into the byte array.
        myStream.Read(Input, 0, fileLen);

        // Copy the byte array to a string.
        for (int loop1 = 0; loop1 < fileLen; loop1++)
        {
            displayString.Append(Input[loop1].ToString());
        }

        //TextBox1.Text = displayString.ToString();
        bytes = ASCIIEncoding.ASCII.GetBytes(dktxt.Text);
        bytes1 = ASCIIEncoding.ASCII.GetBytes(ck);
        
        string originalString = displayString.ToString();

        // DES algorithm to encrypt the given file
        DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
        MemoryStream memoryStream = new MemoryStream();
        CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes1), CryptoStreamMode.Write);
        StreamWriter writer = new StreamWriter(cryptoStream);
        writer.Write(originalString);
        writer.Flush();
        cryptoStream.FlushFinalBlock();
        writer.Flush();

        // store the encrypted data of a file
        cryptedString = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);

推荐答案

以下链接可以解决您的问题,请参阅



[

查看此链接 [ ^ ]

]
Following link can solve your problem please see that

[
See this link[^]
]


我也试过了。但它需要存储并从默认位置获取文件。
i tried that too. but it needs to store and get the files from default location.


这篇关于在asp.net中使用DES进行文件解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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