473,395 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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(ByVal Value As String) As String

Dim ct As ICryptoTransform

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV)

byt = Convert.FromBase64String(Value)

ms = New MemoryStream

cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)

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

cs.FlushFinalBlock()

cs.Close()

Return Encoding.UTF8.GetString(ms.ToArray())

End Function

Public Function EncryptString(ByVal Value As String) As String

Dim ct As ICryptoTransform

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV)

byt = Encoding.UTF8.GetBytes(Value)

ms = New MemoryStream

cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)

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

cs.FlushFinalBlock()

cs.Close()

Return Convert.ToBase64String(ms.ToArray())

End Function
Nov 22 '05 #1
1 1463

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.CreateDecryptor(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(ByVal Value As String) As String

Dim ct As ICryptoTransform

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV)

byt = Convert.FromBase64String(Value)

ms = New MemoryStream

cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)

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

cs.FlushFinalBlock()

cs.Close()

Return Encoding.UTF8.GetString(ms.ToArray())

End Function

Public Function EncryptString(ByVal Value As String) As String

Dim ct As ICryptoTransform

Dim ms As MemoryStream

Dim cs As CryptoStream

Dim byt() As Byte

ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV)

byt = Encoding.UTF8.GetBytes(Value)

ms = New MemoryStream

cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)

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

cs.FlushFinalBlock()

cs.Close()

Return Convert.ToBase64String(ms.ToArray())

End Function

Nov 23 '05 #2

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

Similar topics

2
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)...
14
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...
113
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...
2
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...
7
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...
4
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...
8
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...
22
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...
19
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...
3
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.