Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Encrypted data sending and recieving software

$
0
0
Is there any possible way to make a software in which you first encrypt text and then save it or email it to someone else who will be able to view to data in its decrypted form. I tried the RSA encryption but i was unsicessful. Heres my code but it does not work. Can anyone help me?
'Import the cryptography namespaces
Imports System.Security.Cryptography
Imports System.Text

Public Class Form1
    'Declare global variables
    Dim textbytes, encryptedtextbytes As Byte()
    Dim TextToDecrypt, TextToEncrypt, decrypted, encrypted As String
    Dim encoder As New UTF8Encoding
    'Declare key variables
    Dim cp As New CspParameters

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Define data to be encrypted
        TextToEncrypt = TextBox1.Text
        'Call encryption procedure
        encrypt()
        'Output result
        TextBox2.Text = encrypted
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Define data to be decrypted
        TextToDecrypt = TextBox2.Text
        'Call decryption procedure
        decrypt()
        'Output result
        TextBox3.Text = decrypted
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Set cp container name and tell it to use the information at the computer's key store
        cp.Flags = CspProviderFlags.UseMachineKeyStore
        cp.KeyContainerName = "CryptKeyCon"
        TextBox3.Hide()
        TextBox4.Hide()
        Button3.Hide()
    End Sub
    Sub encrypt()
        'Declare cryption provider
        Dim rsa As New RSACryptoServiceProvider(cp)

        'Use UTF8 to convert the text string into a byte array
        textbytes = Encoder.GetBytes(TextToEncrypt)
        'Encrypt the text
        encryptedtextbytes = rsa.Encrypt(textbytes, True)
        'Convert the encrypted byte array into a Base64 string for display purposes
        encrypted = Convert.ToBase64String(encryptedtextbytes)
    End Sub

    Sub decrypt()
        'Declare cryption provider
        Dim rsa As New RSACryptoServiceProvider(cp)

        'Convert the Base64 string to encrypted byte array for decryption
        encryptedtextbytes = Convert.FromBase64String(TextToDecrypt)
        'Get the decrypted clear text byte array
        textbytes = rsa.Decrypt(encryptedtextbytes, True)
        'Convert the byte array to text using the same encoding format that was used for encryption
        decrypted = encoder.GetString(textbytes)
    End Sub
End Class

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>