Solved

# calculating legth of triple DES  encrypted string

Posted on 2009-04-07
475 Views
I am encrypting a varchar(30) column and storing in a different column in the database.

I need to calculate what the maximum length of the encrypted text could be so that I can make sure the new column is the right size. How do I calculate the size?

I am using vb.net to do the encryption and SQL server 2005 to store the data.
0
Question by:darrenwright
• 3
• 2

LVL 12

Expert Comment

for a 30 character string it will be approximately 36 chars. you can use the following caluculation to calculate the length n + 8 - (n % 8)
where n is the length of the source string
0

Author Comment

I'm get back encryption strings of 88 chars so something not right
0

LVL 12

Expert Comment

0

Author Comment

I use encrypttostring function
``````        Public Overloads Function EncrypttoString(ByVal plainText As String) As String

Return Convert.ToBase64String(Encrypt(plainText))

End Function

Public Function Encrypt(ByVal plainText As String) As Byte()

Dim tdes As New TripleDESCryptoServiceProvider()

Dim encryptor As ICryptoTransform = tdes.CreateEncryptor(mvarTripleDesKey, mvarTripleIV)

Dim data As Byte() = Encoding.Unicode.GetBytes(plainText)

Return encryptor.TransformFinalBlock(data, 0, data.Length)

End Function
``````
0

LVL 12

Accepted Solution

udayakumarlm earned 500 total points
you are using three conversions (for 30 chars)
1.  unicode ( 30 *2 = 60)
2.encryption ( 60 +8 (60 % 8) = 64 (63.2))
3. Base64 Encoding (88)  calculated as Base64 = ((64 + 3 - (64 MOD 3)) /3) x 4

0

## Featured Post

### Suggested Solutions

Cybersecurity has become the buzzword of recent years and years to come. The inventions of cloud infrastructure and the Internet of Things has made us question our online safety. Let us explore how cloud- enabled cybersecurity can help us with our bâ€¦
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filledâ€¦