How to convert Java's SecretKeySpec "DESede" to VB.NET?

730 views Asked by At

I'm having trouble converting the java code to VB.NET

SecretKeySpec skey = new SecretKeySpec(key, "DESede");

any idea ? Thanks :)

2

There are 2 answers

0
Justin Ryan On BEST ANSWER
Dim skey As SecretKeySpec = New SecretKeySpec(key, "DESede")

Of course, getting this to work properly depends on how you translated the SecretKeySpec definition.

0
Ted On
Public Function GenerateTripleDesKey() As Byte()
    Dim rng As New RNGCryptoServiceProvider()
    Dim tripleDesKey As Byte() = New Byte(23) {}
    rng.GetBytes(tripleDesKey)
    For i As Integer = 0 To tripleDesKey.Length - 1
        Dim keyByte As Integer = tripleDesKey(i) And &HFE
        Dim parity = 0
        Dim b As Integer = keyByte
        While b <> 0
            parity = parity Xor b And 1
            b >>= 1
        End While
        tripleDesKey(i) = CByte(keyByte Or (If(parity = 0, 1, 0)))
    Next
    Return tripleDesKey
End Function