Click here to Skip to main content
15,903,012 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: math challenge Pin
santi nuñez30-Apr-18 6:43
santi nuñez30-Apr-18 6:43 
GeneralRe: math challenge Pin
Richard MacCutchan30-Apr-18 6:53
mveRichard MacCutchan30-Apr-18 6:53 
GeneralRe: math challenge Pin
santi nuñez30-Apr-18 6:55
santi nuñez30-Apr-18 6:55 
GeneralRe: math challenge Pin
Richard Deeming30-Apr-18 7:02
mveRichard Deeming30-Apr-18 7:02 
GeneralRe: math challenge Pin
santi nuñez30-Apr-18 9:37
santi nuñez30-Apr-18 9:37 
QuestionAdjusting a .VBS/.DOS command. Pin
glenn masters28-Apr-18 1:40
glenn masters28-Apr-18 1:40 
AnswerRe: Adjusting a .VBS/.DOS command. Pin
Eddy Vluggen30-Apr-18 1:26
professionalEddy Vluggen30-Apr-18 1:26 
QuestionVB.NET encryption code to VB6 Pin
Member 305688623-Apr-18 22:57
Member 305688623-Apr-18 22:57 
Hi,
I would need the following encryption/decryption source to work in VB6.

Public Function Encrypt(ByVal plainText As String) As String

        Dim passPhrase As String = "1234567890"
        Dim saltValue As String = "0987654321"
        Dim hashAlgorithm As String = "SHA1"

        Dim passwordIterations As Integer = 2
        Dim initVector As String = "@1B2c3D4e5F6g7H8"
        Dim keySize As Integer = 256

        Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
        Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)

        Dim plainTextBytes As Byte() = Encoding.UTF8.GetBytes(plainText)


        Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)

        Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
        Dim symmetricKey As New RijndaelManaged()

        symmetricKey.Mode = CipherMode.CBC

        Dim encryptor As ICryptoTransform = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes)

        Dim memoryStream As New IO.MemoryStream()
        Dim cryptoStream As New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)

        cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
        cryptoStream.FlushFinalBlock()
        Dim cipherTextBytes As Byte() = memoryStream.ToArray()
        memoryStream.Close()
        cryptoStream.Close()
        Dim cipherText As String = Convert.ToBase64String(cipherTextBytes)
        Return cipherText
    End Function

    Public Function Decrypt(ByVal cipherText As String) As String
        Dim passPhrase As String = "1234567890"
        Dim saltValue As String = "0987654321"
        Dim hashAlgorithm As String = "SHA1"

        Dim passwordIterations As Integer = 2
        Dim initVector As String = "@1B2c3D4e5F6g7H8"
        Dim keySize As Integer = 256
        ' Convert strings defining encryption key characteristics into byte
        ' arrays. Let us assume that strings only contain ASCII codes.
        ' If strings include Unicode characters, use Unicode, UTF7, or UTF8
        ' encoding.
        Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
        Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)

        ' Convert our ciphertext into a byte array.
        Dim cipherTextBytes As Byte() = Convert.FromBase64String(cipherText)

        ' First, we must create a password, from which the key will be 
        ' derived. This password will be generated from the specified 
        ' passphrase and salt value. The password will be created using
        ' the specified hash algorithm. Password creation can be done in
        ' several iterations.
        Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)

        ' Use the password to generate pseudo-random bytes for the encryption
        ' key. Specify the size of the key in bytes (instead of bits).
        Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)

        ' Create uninitialized Rijndael encryption object.
        Dim symmetricKey As New RijndaelManaged()

        ' It is reasonable to set encryption mode to Cipher Block Chaining
        ' (CBC). Use default options for other symmetric key parameters.
        symmetricKey.Mode = CipherMode.CBC

        ' Generate decryptor from the existing key bytes and initialization 
        ' vector. Key size will be defined based on the number of the key 
        ' bytes.
        Dim decryptor As ICryptoTransform = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)

        ' Define memory stream which will be used to hold encrypted data.
        Dim memoryStream As New IO.MemoryStream(cipherTextBytes)

        ' Define cryptographic stream (always use Read mode for encryption).
        Dim cryptoStream As New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)

        ' Since at this point we don't know what the size of decrypted data
        ' will be, allocate the buffer long enough to hold ciphertext;
        ' plaintext is never longer than ciphertext.
        Dim plainTextBytes As Byte() = New Byte(cipherTextBytes.Length - 1) {}

        ' Start decrypting.
        Dim decryptedByteCount As Integer = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)

        ' Close both streams.
        memoryStream.Close()
        cryptoStream.Close()

        ' Convert decrypted data into a string. 
        ' Let us assume that the original plaintext string was UTF8-encoded.
        Dim plainText As String = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount)

        ' Return decrypted string.   
        Return plainText
    End Function

AnswerRe: VB.NET encryption code to VB6 Pin
Jochen Arndt24-Apr-18 0:48
professionalJochen Arndt24-Apr-18 0:48 
AnswerRe: VB.NET encryption code to VB6 Pin
Chris Quinn24-Apr-18 4:40
Chris Quinn24-Apr-18 4:40 
QuestionFlat NumericUpDown Pin
jtpaa19-Apr-18 20:03
jtpaa19-Apr-18 20:03 
AnswerRe: Flat NumericUpDown Pin
Maciej Los23-Apr-18 10:08
mveMaciej Los23-Apr-18 10:08 
QuestionGetting Run-time error '9' for Subscript out of range Pin
Member 1378560917-Apr-18 23:41
Member 1378560917-Apr-18 23:41 
AnswerRe: Getting Run-time error '9' for Subscript out of range Pin
Richard MacCutchan17-Apr-18 23:58
mveRichard MacCutchan17-Apr-18 23:58 
Questionextracting data problem to ms exel and access database location different in some system Pin
lazy_dude16-Apr-18 2:15
lazy_dude16-Apr-18 2:15 
AnswerRe: extracting data problem to ms exel and access database location different in some system Pin
Jochen Arndt16-Apr-18 3:32
professionalJochen Arndt16-Apr-18 3:32 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
lazy_dude18-Apr-18 4:23
lazy_dude18-Apr-18 4:23 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
Jochen Arndt18-Apr-18 4:50
professionalJochen Arndt18-Apr-18 4:50 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
lazy_dude18-Apr-18 4:51
lazy_dude18-Apr-18 4:51 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
Richard MacCutchan18-Apr-18 5:55
mveRichard MacCutchan18-Apr-18 5:55 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
lazy_dude23-Apr-18 6:55
lazy_dude23-Apr-18 6:55 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
Richard MacCutchan23-Apr-18 7:00
mveRichard MacCutchan23-Apr-18 7:00 
Questionmy program running on background makes my current open application in desktop to blink blink such excel , google, outlook etc. Pin
Member 1280941214-Apr-18 13:38
Member 1280941214-Apr-18 13:38 
AnswerRe: my program running on background makes my current open application in desktop to blink blink such excel , google, outlook etc. Pin
Richard MacCutchan14-Apr-18 21:10
mveRichard MacCutchan14-Apr-18 21:10 
GeneralRe: my program running on background makes my current open application in desktop to blink blink such excel , google, outlook etc. Pin
Member 1280941215-Apr-18 8:01
Member 1280941215-Apr-18 8:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.