DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 22 Aug 2007 02:01:34 -0700,    posted on: microsoft.public.dotnet.framework.compactframework        back       

Thread Index
  1    Maciej Wolniewicz


Error during decryption with SymmetricAlgorithm   
Hello Group,

I\m trying to add encryption to my appplication. it will be used to
encrypt communication between device and some external system.
Encryption and decryption works fine when I work with files, but I do
not want to use files, because I will read data from HTTP Stream and
using files adds to much overhead with IO operation. Then I thought
that I will use MemoryStream class like on dexktop application and
there start some problems.
Encryption looks like is working correctly, but I'm getting exception
when I want to decrypt data I'm getting
System.Security.Cryptography.CryptographicException with message:
"Unknown Error '80007001'."

Below is my code that I use.

 Try

Dim enc As System.Security.Cryptography.SymmetricAlgorithm =
System.Security.Cryptography.SymmetricAlgorithm.Create("RC2")
        Dim bKey As Byte() = System.Text.Encoding.UTF8.GetBytes("some
string")
        ReDim Preserve bKey(15)
        enc.Key = bKey

dim data2Encrypt(32) as Byte
Dim rg As System.Security.Cryptography.RandomNumberGenerator =
System.Security.Cryptography.RandomNumberGenerator.Create
        rg.GetBytes(data2Encrypt)

            Dim encryptedData() As Byte
            Using ms As IO.MemoryStream = New IO.MemoryStream()
                Dim cStream As CryptoStream = New CryptoStream(ms,
enc.CreateEncryptor(), CryptoStreamMode.Write)
                cStream.Write(data2Encrypt, 0, data2Encrypt.Length)
                encryptedData = ms.ToArray()
                cStream.Close()
            End Using

            Dim decryptedData(encryptedData.Length - 1) As Byte
            Using ms As IO.MemoryStream = New
IO.MemoryStream(encryptedData)
                Dim cStream As CryptoStream = New CryptoStream(ms,
enc.CreateDecryptor(), CryptoStreamMode.Read)
                cStream.Read(decryptedData, 0, decryptedData.Length)
                cStream.Close()
            End Using

            Catch ex As Exception

        End Try

And here is my StackTrace:

at System.Security.Cryptography.Utils._DecryptData()
at
System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock()
at System.Security.Cryptography.CryptoStream.Read()
at EncryptionTest.fMain.MenuItem5_Click()
at System.Windows.Forms.MenuItem.OnClick()
at System.Windows.Forms.Menu.ProcessMnuProc()
at System.Windows.Forms.Form.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at EncryptionTest.fMain.Main()

Can somebody know what's wrong?

Thanks in advance for your responce.

Reagrds,

Maciej Wolniewicz
Date:Wed, 22 Aug 2007 02:01:34 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us