need help with code to encrypt a string and write it out to a file.
code does not write out to file
=========code== ============
Private Shared ReadOnly encryptionKeyBy tes() As Byte = New Byte() {53, 53, 53, 53, 53, 53, 53, 53}
Private Shared Function GenerateEncrypt edLicFile(ByVal inputText As String, ByVal outputFile As String) As Boolean
Dim outputStream As Stream = Nothing
Dim encryptedStream As Stream = Nothing
Dim result As Boolean = False
Dim des As DESCryptoServic eProvider = New DESCryptoServic eProvider()
des.Key = encryptionKeyBy tes
des.IV = encryptionKeyBy tes
Try
outputStream = New FileStream(outp utFile, FileMode.Create , FileAccess.Writ e, FileShare.None)
Dim desEncryptor As ICryptoTransfor m = des.CreateEncry ptor()
encryptedStream = New CryptoStream(ou tputStream, desEncryptor, CryptoStreamMod e.Write)
Dim contents() As Byte = des.EncryptValu e(inputText)
encryptedStream .Write(contents , 0, contents.Length )
result = True
Finally
If Not encryptedStream Is Nothing Then
encryptedStream .Close()
encryptedStream = Nothing
End If
If Not outputStream Is Nothing Then
outputStream.Cl ose()
outputStream = Nothing
End If
End Try
Return result
End Function 1 932
You will need to call the encryptedStream .Flush() method. Which causes
all unbuffered data to be written.
On Sun, 3 Sep 2006 13:29:28 -0700, "Jon Paal" <Jon[ nospam ]Paal @
everywhere dot comwrote:
>need help with code to encrypt a string and write it out to a file. code does not write out to file
=========code= =============
Private Shared ReadOnly encryptionKeyBy tes() As Byte = New Byte() {53, 53, 53, 53, 53, 53, 53, 53} Private Shared Function GenerateEncrypt edLicFile(ByVal inputText As String, ByVal outputFile As String) As Boolean
Dim outputStream As Stream = Nothing
Dim encryptedStream As Stream = Nothing
Dim result As Boolean = False
Dim des As DESCryptoServic eProvider = New DESCryptoServic eProvider()
des.Key = encryptionKeyBy tes
des.IV = encryptionKeyBy tes
Try
outputStream = New FileStream(outp utFile, FileMode.Create , FileAccess.Writ e, FileShare.None)
Dim desEncryptor As ICryptoTransfor m = des.CreateEncry ptor()
encryptedStream = New CryptoStream(ou tputStream, desEncryptor, CryptoStreamMod e.Write)
Dim contents() As Byte = des.EncryptValu e(inputText)
encryptedStream .Write(contents , 0, contents.Length )
result = True
Finally
If Not encryptedStream Is Nothing Then
encryptedStream .Close()
encryptedStream = Nothing
End If
If Not outputStream Is Nothing Then
outputStream.Cl ose()
outputStream = Nothing
End If
End Try
Return result End Function This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 there is a
method which can generate a same with the same input string?
There is a need to transfer file between to site,and the customer
wish to encrypt these files during transfering,and they want to store
a string into each database at...
|
by: Jean Christophe Avard |
last post by:
Hi! I am designing an application wich comes with image file. These images
are copyrighted and they have to be accessible only from within the
application. At first, I tought I was going to store them in a database, but
since there will be much more than 2go, I'm going to need multiple database,
and it's no good for CPU performance...
I read about encrypting picture instead of storing them in a DB. But I only
found thing about string...
|
by: DazedAndConfused |
last post by:
Can you encrpt a serialized object?
Or am I trying to do something that just doesn't work that way?
I am trying to encrypt a serialized object. I can read and write the object
to a file without a problem(IF I don't encrypt it).
The encryption routine I am using works great when I am just reading in text
and writing out encrypted data/Reading in encrpted data and writing out
decrypted text.
|
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 build
with these methods, will appear to encrypt and decrypt, but the
resulting decrypted file will be corrupted. I tried encrypting a .bmp
file and then decrypting, the resulting decrypted file under .NET 2.0
is garbage, the .NET 1.1 build works...
|
by: lildiapaz |
last post by:
Hi, everyone
I'm developing a c# windows application that allows the user to encrypt any file type. i would like to encrypt the file using a powerful encrypting algorithm. I've tried to use the rinjael, triple des, but it doesn't seem to encrypt certain files at all. Can you please tell me what the problem is. I don't understand why this function doesn't work when I call it and encrypt the file. when I search for the file it still pulls up...
| |
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| |