| NORSYS SOFTWARE © 2012 | NETICA API | C VERSION 5.04

void SetStreamPassword_ns ( | stream_ns* strm, const char* password )

Sets the password that Netica will use for either encrypting an output stream, or for decrypting an input stream.

Encryption/decryption is only possible for certain file formats (e.g., ".neta"). The file format is specified when the stream is created (see NewFileStream_ns or NewMemoryStream_ns). If strm is not for a format that allows encryption/decryption (such as .dne, .cas, .xml, or .txt), then an error will be generated.

If the password supplied for reading an encrypted source is not the same password that was used by Netica to encrypt that source, then an error will be generated when you attempt to read from that source.

Netica will make a copy of password; it won't modify or free the passed string.

Pass NULL for password to remove it, so that subsequent reading/writing from this stream will be without any encryption/decryption.

Version:

Versions 2.26 and later have this function.

See also:

NewFileStream_ns |  | Create new file stream
NewMemoryStream_ns |  | Create new memory stream

Example:

    stream_ns* stream = NewMemoryStream_ns ("myNet.neta", env, NULL);
    SetStreamPassword_ns (stream, "MyPassword123");
    WriteNet_bn (net, stream);   // writes an encrypted file
    long length;
    const char* buf = GetStreamContents_ns (stream, length);  // buf now holds the encrypted net

    stream_ns* stream2 = NewMemoryStream_ns ("myNet.neta", env, NULL);
    SetStreamContents_ns (stream2, buf, length);
    SetStreamPassword_ns (stream2, "MyPassword123");
    net_bn* net2 = ReadNet_bn (stream2, NO_VISUAL_INFO);   // reads the encrypted file

    stream_ns* stream3 = NewMemoryStream_ns ("myNet.neta", env, NULL);
    SetStreamContents_ns (stream3, buf, length);
    SetStreamPassword_ns (stream3, "WrongPassword456");
    net_bn* net3 = ReadNet_bn (stream3, NO_VISUAL_INFO);  // generates error - password is wrong