Thema: Delphi DEC und HMAC-SHA-256

Einzelnen Beitrag anzeigen

Andreas L.
(Gast)

n/a Beiträge
 
#2

Re: DEC und HMAC-SHA-256

  Alt 19. Apr 2010, 12:01
In den Wikipedia-Artikel ist ein super (sogar Pascal ähnlicher) Pseudocode:
Delphi-Quellcode:
function hmac (key, message)
    if (length(key) > blocksize) then
        key = hash(key) // keys longer than blocksize are shortened
    else if (length(key) < blocksize) then
        key = key ∥ zeroes(blocksize - length(key)) // keys shorter than blocksize are zero-padded
    end if
    
    opad = [0x5c * blocksize] ⊕ key // Where blocksize is that of the underlying hash function
    ipad = [0x36 * blocksize] ⊕ key // Where ⊕ is exclusive or (XOR)
    
    return hash(opad ∥ hash(ipad ∥ message)) // Where ∥ is concatenation
end function
Da brauchst nicht viel ändern. Anstatt der Funktion Hash verwendest einfach SHA256 aus dem DEC.
  Mit Zitat antworten Zitat