Home page  

Products

CipherLite.NET

CipherSafe.NET

Downloads

Resources

Articles

Libraries

Samples

Site Map

BIGGER FONTsmaller font

How To: Use CipherSafe™ API to Perform Administrative Tasks (C#/VB.NET)

The code below demonstrates how to use the CipherSafe™ API, to perfrom various administrative tasks. Code samples are provided in C# and Visual Basic.NET.


C# code

[printer-friendly version]
///////////////////////////////////////////////////////////////////////////////
// SAMPLE: Using CipherSafe to perform administrative task.
//
// This sample requires CipherSafe.NET to be installed on the system.
// To run the sample, create a new Visual C# project using the Console
// Application template and replace the contents of the Class1.cs file with
// the code below. Add a reference to CipherSafe.dll, which should be
// installed by default to C:\Program Files\Obviex\CipherSafe folder (the
// installation folder may include product version number).
//
// Run the application in debug mode setting breakpoints after each operation.
// When code execution stops at breakpoint, verify changes using the
// CipherSafe.NET GUI tool. The user executing this code must be a member
// of the local Administrators or Power Users group.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// 
// Copyright (C) 2002 Obviex(TM). All rights reserved.
// 
using System;
using Obviex.CipherSafe;

/// <summary>
/// Illustrates administrative functionality of CipherSafe API.
/// </summary>
public class CipherSafeAdminDemo
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
        try
        {
            // Get a list of application types.
            ApplicationTypeList appTypes = new ApplicationTypeList();

            // Iterate through all application types in the list.
            foreach (ApplicationType appType in appTypes)
            {
                // Declare application profile.
                ApplicationProfile app;
                
                // Create an application profile for this application type.
                app = ApplicationProfile.Create(
                                            appType.Type,   // type
                                            "Test",         // name
                                            @"c:\dummy");   // path
                                        
                // Define nine values for this application profile.
                for (int i=1; i<=9; i++)
                {
                    app[String.Format("Value #{0}", i)] =
                        String.Format("Data #{0}", i);
                }
                
                // Update every other value.
                for (int i=1; i<=9; i += 2)
                {
                    app[String.Format("Value #{0}", i)] =
                        String.Format("New Data #{0}", i);
                }
                
                // Delete every other value.
                for (int i=2; i<=9; i += 2)
                {
                    app[String.Format("Value #{0}", i)] = null;
                }
                
                // Rename application profiles of defined directories.
                if (ApplicationType.IsDir(app.Type))
                    app.Update("New Test");
            }
            
            // Iterate through all application types in the list.
            foreach (ApplicationType appType in appTypes)
            {
                Console.WriteLine(appType.Name.ToUpper());
                
                // Declare application profile list.
                ApplicationProfileList apps;
                
                // Get application profiles for a given application type.
                apps = new ApplicationProfileList(appType.Type);

                // Iterate through each application profile.
                foreach (ApplicationProfile app in apps)
                {
                    Console.WriteLine("  "     + 
                                      app.Name + 
                                      " ("     + 
                                      app.Path + 
                                      ")");
                    
                    // Iterate through each defined profile value.
                    foreach (ProfileItem item in app)
                    {
                        // Print name and encrypted value of the item.
                        Console.WriteLine("    "    +
                                          item.Name + 
                                          " = "     +
                                          item.Value);
                    }
                    
                    // Delete application profiles of files.
                    if (ApplicationType.IsFile(app.Type))
                        app.Delete();
                }                
            }
            
            // Delete all profiles under Web Applications.
            // ApplicationType.DeleteApplicationProfiles(Category.WebApp);
            
            // Delete all application profiles
            // ApplicationType.DeleteAllApplicationProfiles();
        }
        catch (DetailedException ex)
        {
            // Show all error messages.
            Console.WriteLine(ex.Messages);
        }
        catch (Exception ex)
        {
            // Show immediate error message.
            Console.WriteLine(ex.Message);
        }
    }
}
//
// END OF FILE
///////////////////////////////////////////////////////////////////////////////

^ Back to top  


VB.NET code

[printer-friendly version]
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SAMPLE: Using CipherSafe to retrieve application profile values.
'
' This sample requires CipherSafe.NET to be installed on the system.
' To run the sample, create a new Visual Basic.NET project using the Console
' Application template and replace the contents of the Module1.vb file with
' the code below. Add a reference to CipherSafe.dll, which should be
' installed by default to C:\Program Files\Obviex\CipherSafe folder (the
' installation folder may include product version number).
'
' Run the application in debug mode setting breakpoints after each operation.
' When code execution stops at breakpoint, verify changes using the
' CipherSafe.NET GUI tool. The user executing this code must be a member
' of the local Administrators or Power Users group.
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' 
' Copyright (C) 2002 Obviex(TM). All rights reserved.
'
Imports System
Imports Obviex.CipherSafe

Module Module1

    ' <summary>
    ' The main entry point for the application.
    ' </summary>
    Sub Main()

        Try
            ' Declare variables.
            Dim i       As Integer
            Dim appType As ApplicationType

            ' Get a list of application types.
            Dim appTypes As New ApplicationTypeList()

            ' Iterate through all application types in the list.
            For Each appType In appTypes
            
                ' Declare application profile.
                Dim app As ApplicationProfile
                
                ' Create an application profile for this application type.
                app = ApplicationProfile.Create(          _
                                            appType.Type, _
                                            "Test",       _
                                            "c:\dummy")
                

                ' Define nine values for this application profile.
                For i=1 To 9
                    app(String.Format("Value #{0}", i)) = _
                        String.Format("Data #{0}", i)
                Next
                
                ' Update every other value.
                For i=1 To 9 Step 2
                    app(String.Format("Value #{0}", i)) = _
                        String.Format("New Data #{0}", i)
                Next
                
                ' Delete every other value.
                For i=2 To 9 Step 2
                    app(String.Format("Value #{0}", i)) = Nothing
                Next
                
                ' Rename application profiles of defined directories.
                If (ApplicationType.IsDir(app.Type) = True) Then
                    app.Update("New Test")
                End If
            Next
            
            ' Iterate through all application types in the list.
            For Each appType In appTypes
                Console.WriteLine(appType.Name.ToUpper())
                
                ' Declare application profile list.
                Dim apps As ApplicationProfileList
                
                ' Get application profiles for a given application type.
                apps = New ApplicationProfileList(appType.Type)

                ' Iterate through each application profile.
                Dim app As ApplicationProfile
                For Each app In apps
                    Console.WriteLine("  "     & _
                                      app.Name & _  
                                      " ("     & _
                                      app.Path & _
                                      ")")
                    
                    ' Iterate through each defined profile value.
                    Dim item As ProfileItem
                    For Each item in app
                        ' Print name and encrypted value of the item.
                        Console.WriteLine("    "    & _
                                          item.Name & _
                                          " = "     & _
                                          item.Value)
                    Next
                    
                    ' Delete application profiles of files.
                    If (ApplicationType.IsFile(app.Type) = True) Then
                        app.Delete()
                    End If
                Next               
            Next
            
            ' Delete all profiles under Web Applications.
            ' ApplicationType.DeleteApplicationProfiles(Category.WebApp)
            
            ' Delete all application profiles
            ' ApplicationType.DeleteAllApplicationProfiles()
        Catch ex As DetailedException
        
            ' Show all error messages.
            Console.WriteLine(ex.Messages)
        
        Catch ex As Exception
        
            ' Show immediate error message.
            Console.WriteLine(ex.Message)
        End Try
    End Sub
End Module
'
' END OF FILE
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

^ Back to top

Copyright © 2002-2010 Obviex™ | All rights reserved | Legal | Privacy | Contact us