HashCryptStreams SFStreamCrypt object
 

1. Creation and ProgID
2. Overview
3. Members reference
See also: Stream filter concepts 

Creation and ID-s

Threading model: Both
Program ID: newObjects.crypt.SFStreamCrypt
ClassID: {09B9DCA5-403C-4CFA-933B-88EFD99A4495}
Threading model: Free
ProgramID: newObjects.crypt.SFStreamCrypt.free
ClassID: {A2F1F6FB-4FEC-49c8-88D3-B6ADBFE5A396}

Overview

Supported interfaces

IStream - Can be read/written and otherwise manipulated trough a SFStream object. 

Typical usage template:
Set crypt = Server.CreateObject("newObjects.crypt.SFStreamCrypt")
Set strm = Server.CreateObject("newObjects.utilctls.SFStream")
' Assume otherstream variable holds another object supporting IStream or another SFStream object
Set crypt = otherstream
strm.SetStream crypt
' ... Prepare crypt for usage ...
'    Such as - specify write/read direction encryption algorithm(s), 
'    Read and/or Write direction encryption
'    keys etc.
strm.WriteBin ...
strm.WriteText ...
v = strm.ReadBin(...)
v = strm.ReadText(...) 

Members Reference

method.gif (107 bytes) ReadReset
WriteReset
Syntax:
object.ReadReset
object.WriteReset

Resets the Read or the Write direction data processor respectively. The key and the selected algorithm for the processor being reset are preserved. After calling the method you can start encrypting/decrypting new data through the stream filter. 
method.gif (107 bytes) ReadResetKey
WriteResetKey
Syntax:
object.ReadResetKey
object.WriteResetKey

Resets the Read or the Write direction data processor respectively. The corresponding key is cleared too. The selected algorithm for the processor being reset is  preserved. After calling the method you can set a new key for the corresponding processor (ReadKey or WriteKey respectively) and  start encrypting/decrypting new data through the stream filter.
method.gif (107 bytes) ReadFinalize
WriteFinalize
Syntax:
object.ReadFinalize
object.WriteFinalize

Finalizes the data processing for the Read or Write direction respectively. See also the details in the overview.
WriteDecrypt
ReadDecrypt
Boolean property.
Syntax:
object.WriteDecrypt = b
b = object.WriteDecrypt

By default ReadDecrypt is True and WriteDecrypt is False. This property controls which operation is performed when data is transferred through the stream filter in the respective direction. If the property is False then encryption is performed, if it is True decryption is performed.
SeekingForbidden Boolean property. By default it is set to True.
Syntax:
object.SeekingForbidden = b
b = object.SeekingForbidden

Enables/disables the seeking (repositioning) capabilities of the stream. A value of True means that seeking is forbidden and the stream can be used for sequential read/write operations only.
Note: It is crucial to keep the stream non-seekable while data is encrypted/decrypted. Sometimes the data being encrypted/decrypted may be spread in different places in the stream (file). If you are sure you know what you are doing you can enable seeking (by setting the property to False) and change the stream position in the middle of the processing to the next part of the data being processed, but you must be very careful and not break the sequence in which the data should be encrypted/decrypted. This may be quite complicated calculation (depending on how sparse the data is), thus It is recommended to implement such tasks (processing sparse data in a stream) in more generic way using the Symmetric object. This way will require slightly more code but will be times easier to program.
codePage Syntax:
object.CodePage = cp
cp = object.CodePage

 
WriteDecrypt
ReadDecrypt
Boolean properties.
Syntax:
object.ReadDecrypt = b
b = object.ReadDecrypt

Specify the operation to be performed for the Read and Write direction respectively. By default ReadDecrypt is True and WriteDecrypt is False. I.e. by default the stream filter decrypts on read and encrypts on write. The application can change that as needed.
ReadPadType
WritePadType
Syntax:
object.ReadPadType = n
n = object.ReadPadtype

Specifies how to pad the data (for the Read or the Write direction respectively) if it does not fit a complete buffer size when the encryption is finalized. If set to value between 0 and 255 bytes with that value are repeated to pad the data. If -1 is specified random bytes are generated. 

Stream Syntax:
Set object.Stream = strm
Set strm = object.Stream

Specifies the underlying stream over which the stream filter works. I.e. When Read or Written the SFStreamCrypt actually reads from or writes to this stream performing (before write and after read respectively) additional processing - encryption/decryption according to the specified algorithm and the value of the WriteDecrypt and ReadDecrypt properties.
The SFStreamCrypt can work over any object that supports the IStream interface or over a SFStream object.
ReadAlgorithm
WriteAlgorithm
Syntax:
object.ReadAlgoritm = algname
alg = object.ReadAlgoritm

A string property - specifies the algorithm used for Read and Write direction respectively. When written it also resets the internal buffers and state for the corresponding direction. The supported algorithms are the same as for the Symmetric.Init method:
AES - Advanced Encryption Standard.
DES - DES or 3DES depending on the length of the key specified.

Remarks: If no algorithm is set for a given direction the SFStreamCrypt will do nothing and will just relay the information from/to the underlying stream (see the Stream property). To clear a previously set algorithm call ReadReset or WriteReset.

ReadKey
WriteKey
Syntax:
object.ReadKey = k
k = object.ReadKey

Specifies the key for the selected (with ReadAlgorithm or WriteAlgoritm property) encryption algorithm. Ignored if the algorithm does not use a key (for example for an encoding algorithm).
The different algorithms require specific key lengths. Here is the list:
AES - The key can be 16, 24 or 32 bytes.
DES - The key can be 8, 16 or 24 bytes. Note that 16 and 24 byte keys cause 3DES to be performed.

...

newObjects Copyright 2001-2006 newObjects [ ]