473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

encryption help

Hi All,

i am using the following two functions to encrypt data, bank details. i can
encrypt the details no problems. but when i try to decrypt the details i
get the following error

"PKCS7 padding is invalid and cannot be removed"

does anybody know i can encrypt and decrypt data from a database ? any
pointers would be greatfully appreciated!!

Many thanks

Simon Whale

P.S using vb.net 2003 and sql server 200

Public Function DecryptString(B yVal Value As String) As String

Dim ct As ICryptoTransfor m

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateDecr yptor(mCSP.Key, mCSP.IV)

byt = Convert.FromBas e64String(Value )

ms = New MemoryStream

cs = New CryptoStream(ms , ct, CryptoStreamMod e.Write)

cs.Write(byt, 0, byt.Length)

cs.FlushFinalBl ock()

cs.Close()

Return Encoding.UTF8.G etString(ms.ToA rray())

End Function

Public Function EncryptString(B yVal Value As String) As String

Dim ct As ICryptoTransfor m

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateEncr yptor(mCSP.Key, mCSP.IV)

byt = Encoding.UTF8.G etBytes(Value)

ms = New MemoryStream

cs = New CryptoStream(ms , ct, CryptoStreamMod e.Write)

cs.Write(byt, 0, byt.Length)

cs.FlushFinalBl ock()

cs.Close()

Return Convert.ToBase6 4String(ms.ToAr ray())

End Function
Nov 22 '05 #1
1 1472

Simon -

Well... I do not know for sure, since the provided code is incomplete, but i
believe that the problem has to do with the IV. The IV should be different
for every cipher text. This means that the IV needs to be known to the
function performing the decryption. It looks like your code:

ct = mCSP.CreateDecr yptor(mCSP.Key, mCSP.IV)

generates a new IV during the decryption process [maybe? I dont really know
since mCSP is not defined in the code provided]

In applications I have written, the IV is included in the cipher text as
plaintext.
"Simon Whale" wrote:
Hi All,

i am using the following two functions to encrypt data, bank details. i can
encrypt the details no problems. but when i try to decrypt the details i
get the following error

"PKCS7 padding is invalid and cannot be removed"

does anybody know i can encrypt and decrypt data from a database ? any
pointers would be greatfully appreciated!!

Many thanks

Simon Whale

P.S using vb.net 2003 and sql server 200

Public Function DecryptString(B yVal Value As String) As String

Dim ct As ICryptoTransfor m

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateDecr yptor(mCSP.Key, mCSP.IV)

byt = Convert.FromBas e64String(Value )

ms = New MemoryStream

cs = New CryptoStream(ms , ct, CryptoStreamMod e.Write)

cs.Write(byt, 0, byt.Length)

cs.FlushFinalBl ock()

cs.Close()

Return Encoding.UTF8.G etString(ms.ToA rray())

End Function

Public Function EncryptString(B yVal Value As String) As String

Dim ct As ICryptoTransfor m

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateEncr yptor(mCSP.Key, mCSP.IV)

byt = Encoding.UTF8.G etBytes(Value)

ms = New MemoryStream

cs = New CryptoStream(ms , ct, CryptoStreamMod e.Write)

cs.Write(byt, 0, byt.Length)

cs.FlushFinalBl ock()

cs.Close()

Return Convert.ToBase6 4String(ms.ToAr ray())

End Function

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2144
by: gaurav khanna | last post by:
Hi I need to store the credit card information in my database. I have been looking for some third party tools which could provide encryption for credit card numbers. The help I need is: a) What is the most secure encryption tool that can be used to store credit card information?
14
1954
by: Ray Cassick \(Home\) | last post by:
Ok, time to ask the question here.. I have been battling over this one for sometime now and just have to ask it. I have created a few classes that I use to act a security keys. These classes get serialized using a binary formatter and then symmetrically encrypted. The app will deserialize them and use the contents to judge licensing capabilities, etc. Currently the license key and vectors are stored in the code. I don't like the idea...
113
12360
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
2
7153
by: almurph | last post by:
Hi everyone, Can you help me please? I am having a problem with the encryption/decryption of words with the Irish fada in them. The Irish fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the French grave... Anyway when I run encryption on a plaintext word like:
7
6150
by: Steven Cliff | last post by:
I have started to use the new Enterprise Library (Jan 06) and have set up a skeleton project using the DAAB. This all seems to work fine apart from when I come to secure the app.config file via encryption. I have encrypted the connectionsettings block in the config file but obviously when I come to deploy the solution to other PC's, it cannot read the block as it doesn't have the keys to decrypt. I understand that as far as ASP.NET...
4
4148
by: pintu | last post by:
Hello everybody.. I hav some confusion regarding asymmetric encryption.As asymmetric encryption it there is one private key and one public key.So any data is encrypted using private key and the same is decrypted at client side using public key and vice-versa..Now i hav confusion like i.e. * Are both the keys available to both sender and receiver.? * When data is encrypted using public key ,Is the same data decrypted using private key(...
8
2748
by: manmit.walia | last post by:
Hello Everyone, Long time ago, I posted a small problem I had about converting a VB6 program to C#. Well with the help with everyone I got it converted. But I overlooked something and don't understand why it is doing this. Below is my code, I would be greatfull if someone can guide me through the right path or even help me solve this issue. Problem: The old tool which was written in VB6 works perfect. But I needed to convert this to C#...
22
7700
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look through the code and point me in the correct direction one would be very grateful. Example Input : j1mb0jay Example Output 1 : rZHKZbYZWn/4UgL9mAjN2DUz7X/UpcpRxXM9SO1QkvkOe5nOPEKnZldpsB7uHUNZ Example Output 2 :...
19
3307
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash (md5) the password field using a random one-time salt (nonce) -- generated by php and pasted in the form -- that is then posted with the hashed password
3
3082
by: =?Utf-8?B?TG9yZW4=?= | last post by:
I’m trying to encrypt and decrypt a file in vb.net. I am using the TripleDESCryptoServiceProvider encryption found in System.Security.Cryptography. Below is the code for my Encrypt and Decrypt functions. While my functions read and write files the encryption/decryption is not working properly. My test file has an original length of 66,048 bytes. My encrypted file ends up with 66,056 bytes … 8 bytes more than my original. When I...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.