473,399 Members | 3,401 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,399 software developers and data experts.

Tripple DES Encrypt/Decrypt string Function or Example

Has anyone made a simple tripple des encryption function?

I'm looking for a function to pass a string into with a password and
generate an encrypted output. That's it.

IE. Public Function EncryptMe (StringtoEncrypt, Password)as string
End Function

Public Function DecryptMe (StringtoDecrypt, Password)as string

End Function

or something to this nature? I know this is not reinventing the
wheel.

-Peter
Nov 20 '05 #1
1 8095
Here I found this on the net somewhere. It works as wel

Win

Public Class TripleDE
Private key() As Byte = {1, 2, 3, 4, 5, 6, 255, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
Private iv() As Byte = {65, 110, 68, 26, 69, 178, 200, 219

Public Function Encrypt(ByVal plainText As String) As Byte(
' Declare a UTF8Encoding object so we may use the GetByte
' method to transform the plainText into a Byte array.
Dim utf8encoder As UTF8Encoding = New UTF8Encodin
Dim inputInBytes() As Byte = utf8encoder.GetBytes(plainText

' Create a new TripleDES service provider
Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvide

' The ICryptTransform interface uses the TripleDES
' crypt provider along with encryption key and init vector
' information
Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateEncryptor(Me.key, Me.iv

' All cryptographic functions need a stream to output the
' encrypted information. Here we declare a memory stream
' for this purpose.
Dim encryptedStream As MemoryStream = New MemoryStrea
Dim cryptStream As CryptoStream = New CryptoStream(encryptedStream, cryptoTransform, CryptoStreamMode.Write

' Write the encrypted information to the stream. Flush the information
' when done to ensure everything is out of the buffer.
cryptStream.Write(inputInBytes, 0, inputInBytes.Length
cryptStream.FlushFinalBlock(
encryptedStream.Position =

' Read the stream back into a Byte array and return it to the calling
' method.
Dim result(encryptedStream.Length - 1) As Byt
encryptedStream.Read(result, 0, encryptedStream.Length
cryptStream.Close(
Return resul
End Functio

Public Function Decrypt(ByVal inputInBytes() As Byte) As Strin
' UTFEncoding is used to transform the decrypted Byte Array
' information back into a string.
Dim utf8encoder As UTF8Encoding = New UTF8Encodin
Dim tdesProvider As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvide

' As before we must provide the encryption/decryption key along with
' the init vector.
Dim cryptoTransform As ICryptoTransform = tdesProvider.CreateDecryptor(Me.key, Me.iv

' Provide a memory stream to decrypt information into
Dim decryptedStream As MemoryStream = New MemoryStrea
Dim cryptStream As CryptoStream = New CryptoStream(decryptedStream, cryptoTransform, CryptoStreamMode.Write
cryptStream.Write(inputInBytes, 0, inputInBytes.Length
cryptStream.FlushFinalBlock(
decryptedStream.Position =

' Read the memory stream and convert it back into a string
Dim result(decryptedStream.Length - 1) As Byt
decryptedStream.Read(result, 0, decryptedStream.Length
cryptStream.Close(
Dim myutf As UTF8Encoding = New UTF8Encodin
Return myutf.GetString(result
End Functio
End Clas

----- Peter wrote: ----

Has anyone made a simple tripple des encryption function

I'm looking for a function to pass a string into with a password an
generate an encrypted output. That's it

IE. Public Function EncryptMe (StringtoEncrypt, Password)as strin
End Functio

Public Function DecryptMe (StringtoDecrypt, Password)as strin

End Functio

or something to this nature? I know this is not reinventing th
wheel

-Pete

Nov 20 '05 #2

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

Similar topics

1
by: wqhdebian | last post by:
As far as I know,when encrypt or decrypt ,a key must first be got,and the key is first generate by a tool or from SecurityRandom,that means I can not generate the same key with the same input.Does...
4
by: Spikinsson | last post by:
I'm looking for a good decrypt/encrypt function, all I want is a function in this form: char* encrypt(char* normal) { ... return encrypted; } and
10
by: Javier Gomez | last post by:
I have a table with 15.000 records. How can encrypt all information if after will shown in a form (text box)decryted ????? Thanks in advance Javier Gomez
4
by: Hrvoje Voda | last post by:
Does anyone knows a good example of how to encrypt/decrypt a string? Hrcko
8
by: Gidi | last post by:
Hi, Is there Buid-In fuction in C# that Encrypt and Decrypt strings? i have a textbox which i'm writing into file, and i want to encrypt it before writing, i'm not looking for something fancy,...
8
by: toupeira23 | last post by:
Hello, I'm trying to encrypt passwords in my app. After discovering that there's no simple function to do this, I wrote a wrapper class which decodes a string using UTF8, encrypts it with...
3
by: Dave Cullen | last post by:
Hello C I have a project that requires a calculated "key" to be used in a security access application. The customer supplies a secret 8 byte number that gets combined with the serial number of...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
0
by: FarooqRafiq | last post by:
Hi, My requirement is that a string is encrypted in VB.NET and sent to PHP, PHP decrypts the string (till here the logic is working) and then the PHP should encrtyp (where i am having problems)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.