mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-10-26 18:41:18 +00:00
Implemented the HIGHT block cipher with ECB mode support, including HightAlgorithm, HightCore, and HightEcbTransform classes. Updated the test program to include HIGHT encryption/decryption tests and added support for PaddingMode.None in ARIA and SEED ECB transforms.
51 lines
1.5 KiB
VB.net
51 lines
1.5 KiB
VB.net
Imports System.Security.Cryptography
|
|
|
|
Public Class HightAlgorithm
|
|
Inherits SymmetricAlgorithm
|
|
|
|
Public Sub New()
|
|
LegalBlockSizesValue = New KeySizes() {New KeySizes(64, 64, 0)}
|
|
LegalKeySizesValue = New KeySizes() {New KeySizes(128, 128, 0)}
|
|
|
|
Me.BlockSize = 64
|
|
Me.KeySize = 128
|
|
Me.FeedbackSize = 64
|
|
|
|
Me.Mode = CipherMode.ECB
|
|
Me.Padding = PaddingMode.PKCS7
|
|
|
|
Me.Key = New Byte(15) {}
|
|
Me.IV = New Byte(7) {}
|
|
End Sub
|
|
|
|
Public Overrides Sub GenerateKey()
|
|
Using rng As New RNGCryptoServiceProvider()
|
|
rng.GetBytes(Me.Key)
|
|
End Using
|
|
End Sub
|
|
|
|
Public Overrides Sub GenerateIV()
|
|
Using rng As New RNGCryptoServiceProvider()
|
|
rng.GetBytes(Me.IV)
|
|
End Using
|
|
End Sub
|
|
|
|
Public Overrides Function CreateEncryptor(rgbKey As Byte(), rgbIV As Byte()) As ICryptoTransform
|
|
Return CreateTransform(rgbKey, rgbIV, True)
|
|
End Function
|
|
|
|
Public Overrides Function CreateDecryptor(rgbKey As Byte(), rgbIV As Byte()) As ICryptoTransform
|
|
Return CreateTransform(rgbKey, rgbIV, False)
|
|
End Function
|
|
|
|
Private Function CreateTransform(key As Byte(), iv As Byte(), encrypt As Boolean) As ICryptoTransform
|
|
Select Case Me.Mode
|
|
Case CipherMode.ECB
|
|
Return New HightEcbTransform(key, encrypt, Me.Padding)
|
|
Case Else
|
|
Throw New NotSupportedException("This mode not supported yet")
|
|
End Select
|
|
End Function
|
|
|
|
' TODO: CCM, GCM, CMAC
|
|
End Class |