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 |