Domino 9 und frühere Versionen > ND8: Entwicklung

HMAC SHA256 Encryption

(1/1)

mind1:
Hallo,

ich suche schon seit ein paar Tagen nach einem Ansatz zur Verschlüsselung per Lotus Script. Es geht dabei um eine HMAC SHA256- Verschlüsselung, von der es z.B. in Javascript und PHP Librories gibt. Bei LS habe ich noch nichts finden können.
Die base64.lss habe ich bereits für andere Dinge eingebunden. Geht es evtl damit? Habe leider keine ausführliche Beschreibung dafür.

Wer weiss was?

Vielen Dank!

Gruss, Bernd

pram:
Schau dir mal die "advapi32.dll" an.
http://www.activevb.de/cgi-bin/forenarchive/forenarchive.pl?a=0&b=b&d=94102&e=1
hab damit mal eine MD5 Verschlüsselung gemacht, sollte sich aber auch einfach auf andere Algos umstellen lassen.
http://msdn.microsoft.com/en-us/library/aa380252%28VS.85%29.aspx
http://www.activevb.de/cgi-bin/apiwiki/CryptCreateHash

Gruß
Roland

Edit: habs letztendlich doch ein bisschen anders gemacht.

--- Code: ---Option Public

Option Declare
Private Const MD5_BUF_SIZE = 16384

Private Type MD5_CTX
i (1 To 2) As Long
buf (1 To 4) As Long
inp (1 To 64) As Byte
digest (1 To 16) As Byte
End Type

Private Type MD5_BUFFER
buffer (1 To MD5_BUF_SIZE) As Byte
End Type

Declare Private Function w32_CreateFile Lib "kernel32.dll" Alias "CreateFileA" ( _
Byval lpFileName As Lmbcs String, _
Byval dwDesiredAccess As Long, _
Byval dwShareMode As Long, _
Byval lpSecurityAttributes As Long, _
Byval dwCreationDisposition As Long, _
Byval dwFlagsAndAttributes As Long, _
Byval hTemplateFile) As Long

Declare Private Function w32_ReadFile Lib "kernel32.dll" Alias "ReadFile" (Byval hFile As Long,  buffer As MD5_BUFFER, Byval toRead As Long, readBytes As Long, Byval overlap As Long) As Long
Declare Private Function w32_CloseHandle Lib "kernel32.dll" Alias "CloseHandle" (Byval hFile As Long) As Integer

Declare Private Sub w32_MD5Init Lib "advapi32.dll" Alias "MD5Init" (Context As MD5_CTX)
Declare Private Sub w32_MD5Update Lib "advapi32.dll" Alias "MD5Update" (Context As MD5_CTX, buffer As MD5_BUFFER, Byval lLen As Long)
Declare Private Sub w32_MD5Final Lib "advapi32.dll" Alias "MD5Final" (Context As MD5_CTX)

Public Function MD5ofFile(fileName As String) As String
Dim hFile As Long ' file handle
Dim buffer As MD5_BUFFER
Dim readBytes As Long
Dim ctx As MD5_CTX
' open the file handle
hFile = w32_CreateFile(fileName, _
&H80000000, _ ' GENERIC_READ
1, _ ' FILE_SHARE_READ
0, _
3, _ ' OPEN_EXISTING
&H80, _ ' FILE_ATTRIBUTE_NORMAL
0)

If hFile = -1 Then
Error 10, "Unable to open " + fileName
End If

Call w32_MD5init(ctx)
Do While w32_readFile(hFile, buffer, MD5_BUF_SIZE, readBytes, 0)
If readBytes = 0 Then Exit Do
Call w32_MD5update(ctx, buffer, readBytes)
Loop
Call w32_MD5final(ctx)
w32_CloseHandle(hFile)
Dim i%, ret$
For i = 1 To 16
ret = ret + Right("0" + Hex(ctx.digest(i)),2)
Next
MD5ofFile = Lcase(ret)

End Function

--- Ende Code ---
Es gibt in der DLL auch eine A_SHAinit/update/final. Ich denke das könnte das sein was du suchst

Navigation

[0] Themen-Index

Zur normalen Ansicht wechseln