SIFWorks ADK 2.0
SifEncryption Class
NamespacesEdustructures.SifWorksSifEncryption

[This is preliminary documentation and is subject to change.]

SifEncryption provides easy read and write access to encrypted passwords in the Authentication object
Declaration Syntax
C#Visual BasicVisual C++
public abstract class SifEncryption : IDisposable
Public MustInherit Class SifEncryption _
	Implements IDisposable
public ref class SifEncryption abstract : IDisposable
Members
All MembersMethodsProperties



IconMemberDescription
Algorithm
Returns the algorithm that is currently being used

Dispose()()
Cleans up any unmanaged resources that are being held on to by this instance

static memberGetInstance(PasswordAlgorithm, String, array<Byte>[]())
Creates an instance of SIFEncryption that uses the specified PasswordAlgorithm, keyName and key

static memberGetInstance(Password, IZone)
Creates an instance of SIFEncryption that can decrypt the password field automatically, using settings defined in the agent's properties.

static memberGetInstance(IZone)
Creates an instance of SIFEncryption that can be used for writing the Password field, using settings from the agent's properties

IsHash
Returns true if the value is a hashed value and cannot be decrypted. In this case, the ReadPassword(Password) method will return the hashed value as a Base64 string

Key
Returns the key that the class is currently using to decrypt

KeyName
Returns the name of the key that is currently being used

ReadPassword(Password)
Returns the unencrypted password value from the Password field. If the algorithm in use is a hash algorithm, the Base64 instance of the hash will be returned instead.

WritePassword(Password, String)
Encrypts the specified password and populates the Password field with the algorithm and key name values. This method must be overriden by the specific encryption algorithm to set the actual encrypted value.

Remarks

The SIFEncryption class uses the following properties to determine its default algorithm and key for writing and for finding keys for decrypting passwords. Please see AgentProperties for details

Settings KeyDescription
adk.encryption.algorithm
The default algorithm used for writing passwords
adk.encryption.key
The name of the default key to use for encryption
adk.encryption.keys.[keyname]
The actual key to use for encryption or decryption where “keyname” matches the @KeyName attribute of the Password object
Examples
Here is an example of how a subscriber to the Authentication class could use SifEncryption to read passwords. For more examples, including a provider example, please see the AuthenticationProvider and AuthenticationSubscriber example projects.
CopyVB.NET
Public Sub OnQueryResults(ByVal data As Edustructures.SifWorks.IDataObjectInputStream, _
    ByVal err As Edustructures.SifWorks.Infra.SIF_Error, _
    ByVal zone As Edustructures.SifWorks.IZone, _
    ByVal info As Edustructures.SifWorks.IMessageInfo) _
    Implements Edustructures.SifWorks.IQueryResults.OnQueryResults
    While data.Available
        Dim auth As Authentication = DirectCast(data.ReadDataObject(), Authentication)
        HandleAuthenticationReceived(auth, zone)
    End While
End Sub

Public Sub OnEvent(ByVal evnt As Edustructures.SifWorks.Event, _
    ByVal zone As Edustructures.SifWorks.IZone, _
    ByVal info As Edustructures.SifWorks.IMessageInfo) _
    Implements Edustructures.SifWorks.ISubscriber.OnEvent
    While evnt.Data.Available
        Dim auth As Authentication = DirectCast(evnt.Data.ReadDataObject(), Authentication)
        HandleAuthenticationReceived(auth, zone)
    End While
End Sub

Private Sub HandleAuthenticationReceived(ByVal auth As Authentication, ByVal zone As IZone)
    Dim inf As AuthenticationInfo
    For Each inf In auth.GetAuthenticationInfos()
        Dim decryptor As SifEncryption = SifEncryption.GetInstance(inf.Password, zone)
        Console.WriteLine("Received AuthenticationInfo/Password using algorithm {0} for user {1}, password={2} ", _
        decryptor.Algorithm.ToString(), inf.Username, decryptor.ReadPassword(inf.Password))
        Console.WriteLine()
    Next
End Sub
CopyC#
public void OnQueryResults(Edustructures.SifWorks.IDataObjectInputStream data, 
    Edustructures.SifWorks.Infra.SIF_Error err, 
    Edustructures.SifWorks.IZone zone, 
    Edustructures.SifWorks.IMessageInfo info)
{
    while (data.Available) 
    {
        Authentication auth = ((Authentication)(data.ReadDataObject()));
        HandleAuthenticationReceived(auth, zone);
    }
}

public void OnEvent(Edustructures.SifWorks.Event evnt, 
    Edustructures.SifWorks.IZone zone, 
    Edustructures.SifWorks.IMessageInfo info)
{
    while (evnt.Data.Available) 
    {
        Authentication auth = ((Authentication)(evnt.Data.ReadDataObject()));
        HandleAuthenticationReceived(auth, zone);
    }
}

private void HandleAuthenticationReceived(Authentication auth, IZone zone)
{
    foreach (AuthenticationInfo inf in auth.GetAuthenticationInfos()) 
    {
        SifEncryption decryptor = SifEncryption.GetInstance(inf.Password, zone);
        Console.WriteLine("Received AuthenticationInfo/Password using algorithm {0} for user {1}, password={2} ", 
            decryptor.Algorithm.ToString(), inf.Username, decryptor.ReadPassword(inf.Password));
        Console.WriteLine();
    }
}
Inheritance Hierarchy
Object
SifEncryption
See Also

Assembly: Edustructures.SifWorks.Adk (Module: Edustructures.SifWorks.Adk) Version: 2.0.0.10