HashStream.st
changeset 15621 2a93f0420de1
parent 14842 8f7ca0be2aed
child 15622 79d968fa9f05
equal deleted inserted replaced
15620:264cf9877dda 15621:2a93f0420de1
   169     "Modified (comment): / 09-01-2012 / 21:49:59 / cg"
   169     "Modified (comment): / 09-01-2012 / 21:49:59 / cg"
   170 ! !
   170 ! !
   171 
   171 
   172 !HashStream class methodsFor:'utilities'!
   172 !HashStream class methodsFor:'utilities'!
   173 
   173 
       
   174 cryptBlock:aStringOrByteArray from:srcIdx into:resultOrNil startingAt:dstIdx encrypt:encryptMode
       
   175     "one-way encryption of aStringOrByteArray.
       
   176      Used when a HashStream is used as the block copher with OFB or CTR mode.
       
   177 
       
   178      encryptMode is ignored here."
       
   179 
       
   180     |hashValue|
       
   181 
       
   182     srcIdx == 1 ifTrue:[
       
   183         hashValue := self hashValueOf:aStringOrByteArray.
       
   184     ] ifFalse:[
       
   185         |bytesToEncrypt|
       
   186 
       
   187         bytesToEncrypt := aStringOrByteArray copyFrom:srcIdx to:srcIdx+self hashSize-1.
       
   188         hashValue := self hashValueOf:bytesToEncrypt.
       
   189     ].
       
   190     resultOrNil isNil ifTrue:[
       
   191         ^ hashValue.
       
   192     ] ifFalse:[
       
   193         resultOrNil replaceBytesFrom:dstIdx to:dstIdx+hashValue size-1 with:hashValue startingAt:1.
       
   194         ^ resultOrNil.
       
   195     ].
       
   196 
       
   197     "
       
   198         |cipher iv cipherText|
       
   199 
       
   200         cipher := OfbCipher for:SHA512Stream.
       
   201         iv := cipher randomInitializationVector.
       
   202         cipherText := cipher encrypt:'Hello world, here is the alien from Mars and 1234567890' asByteArray.
       
   203         self information:cipherText printString.
       
   204 
       
   205         cipher initializationVector:iv.
       
   206         self information:(cipher decrypt:cipherText) asString.
       
   207     "
       
   208 !
       
   209 
   174 digestMessage:aStringOrByteArrayOrStream
   210 digestMessage:aStringOrByteArrayOrStream
   175     ^ self hashValueOf:aStringOrByteArrayOrStream
   211     ^ self hashValueOf:aStringOrByteArrayOrStream
   176 !
   212 !
   177 
   213 
   178 hashValueOf:aStringOrByteArrayOrStream
   214 hashValueOf:aStringOrByteArrayOrStream
   387 ! !
   423 ! !
   388 
   424 
   389 !HashStream class methodsFor:'documentation'!
   425 !HashStream class methodsFor:'documentation'!
   390 
   426 
   391 version
   427 version
   392     ^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.27 2013-03-08 23:37:43 stefan Exp $'
   428     ^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.28 2013-08-11 21:53:29 stefan Exp $'
   393 !
   429 !
   394 
   430 
   395 version_CVS
   431 version_CVS
   396     ^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.27 2013-03-08 23:37:43 stefan Exp $'
   432     ^ '$Header: /cvs/stx/stx/libbasic/HashStream.st,v 1.28 2013-08-11 21:53:29 stefan Exp $'
   397 ! !
   433 ! !
   398 
   434