Sync editor encryption pwd

Hi Team,

Below code is still returning encrypted pwd stored in sync editor.


Looks like this piece of code is not working

"' Decrypt the password using the decryption method
Dim decrypter As VI.Projector.Security.DatabaseEncryption = New VI.Projector.Security.DatabaseEncryption(Connection.Session)
pwd = decrypter.Decrypt(pwd)"

Could you please correct my code?

References System.DirectoryServices.dll
Imports System.DirectoryServices
Imports System.DirectoryServices.AccountManagement

References VI.DB.dll
Imports VI.DB
Imports VI.DB.Entities
Imports VI.DB.Scripting
Imports VI.DB.Scripting.ScriptBase

Public Function A_AA_TestBed(ByVal uidVariableSet As String) As String
' Get the username and encrypted password from the system variable
Dim UserName As String = CCC_Get_DPRSystemVariableValue(uidVariableSet, "CP_BASEloginaccount")
Dim Pwd As String = CCC_Get_DPRSystemVariableValue(uidVariableSet, "CP_BASEpassword")

' Decrypt the password using the decryption method
Dim decrypter As VI.Projector.Security.DatabaseEncryption = New VI.Projector.Security.DatabaseEncryption(Connection.Session)
pwd = decrypter.Decrypt(pwd)

' Get the list of AD servers
Dim ServerList As String = CCC_Get_DPRSystemVariableValue(uidVariableSet, "CP_ADServerList")
Dim TargetADServers() As String = ServerList.Split(New Char() {","c}) ' Split the list into an array

' Iterate through all the AD servers in the array

' Loop through each AD server in the list and try to validate credentials
For Each server As String In TargetADServers
Using context As New PrincipalContext(ContextType.Domain, server.Trim())
Dim valid As Boolean = context.ValidateCredentials(UserName, pwd)
If valid Then
' Return the first AD server that successfully validates the credentials
Return server.Trim()
End If
End Using
Next

' If no valid server is found, return nothing (implicitly returns Nothing)
Return Nothing
End Function

Parents
  • Hi,

    Your code looks the same as mine.  Where are you running/testing the script?  It will 'only' work when it runs in a ScriptExec component in a job step in a jobchain that is running on a JobServer service instance that has the encryption key loaded.

    HTH, Barry.

  • Hi Barry,

    Thanks for your response.

    Can I use this script inside sync editor as well as I converted cp_adserver variable to scripted variable.

  • Hi Ayan,

    I'm not sure about that .... I've only ever done this in a script via ScriptExec ...... I don't know what context the scripted variables run under.

    Sorry ..... maybe somebody else knows.

    B.

  • "Can I use this script inside sync editor as well as I converted cp_adserver variable to scripted variable."

    Which part of the script? What are you trying to achieve? What version are you using?

  • I am using below script in sync editor to return DC value

    CP_BASEpassword variable is encrypted and Issecret checked but still below script working

    Does sync editor decrypts variable on its own?

    References System.DirectoryServices.dll
    References System.DirectoryServices.AccountManagement.dll
    Imports System.DirectoryServices.ActiveDirectory
    Imports System.DirectoryServices.AccountManagement

    References VI.DB.dll
    Imports VI.DB
    Imports VI.DB.Entities
    Imports VI.DB.Scripting
    Imports VI.DB.Scripting.ScriptBase

    Dim result As String = ""
    Dim valid As Boolean = False 'Has valid ADServer been found
    Dim UID_DPRSystemVariableSet = VariableSet.Item("CP_UID_DPRSystemVariableSet")
    Dim ServiceName As String = VariableSet.Item("CP_BASEloginaccount")
    Dim ServicePassword As String = VariableSet.Item("CP_BASEpassword")
    Dim ServerList As String = VariableSet.Item("CP_ADServerList")
    Dim TargetADServers() As String = ServerList.Split(New Char() {","c})

    For Each server As String In TargetADServers

    Try
    Using context As New PrincipalContext(ContextType.Domain, server.Trim())
    valid = context.ValidateCredentials(ServiceName, ServicePassword) 'No need to redeclare 'valid' here
    If valid Then
    ' Return the first AD server that successfully validates the credentials
    Return server.Trim()
    End If
    End Using
    Catch ex As Exception
    ' Log the exception or handle it (e.g., move to the next server)
    result = "ERROR: " + ViException.ErrorString(ex)
    End Try
    Next

    ' If no valid server is found, return Nothing
    Return Nothing

Reply
  • I am using below script in sync editor to return DC value

    CP_BASEpassword variable is encrypted and Issecret checked but still below script working

    Does sync editor decrypts variable on its own?

    References System.DirectoryServices.dll
    References System.DirectoryServices.AccountManagement.dll
    Imports System.DirectoryServices.ActiveDirectory
    Imports System.DirectoryServices.AccountManagement

    References VI.DB.dll
    Imports VI.DB
    Imports VI.DB.Entities
    Imports VI.DB.Scripting
    Imports VI.DB.Scripting.ScriptBase

    Dim result As String = ""
    Dim valid As Boolean = False 'Has valid ADServer been found
    Dim UID_DPRSystemVariableSet = VariableSet.Item("CP_UID_DPRSystemVariableSet")
    Dim ServiceName As String = VariableSet.Item("CP_BASEloginaccount")
    Dim ServicePassword As String = VariableSet.Item("CP_BASEpassword")
    Dim ServerList As String = VariableSet.Item("CP_ADServerList")
    Dim TargetADServers() As String = ServerList.Split(New Char() {","c})

    For Each server As String In TargetADServers

    Try
    Using context As New PrincipalContext(ContextType.Domain, server.Trim())
    valid = context.ValidateCredentials(ServiceName, ServicePassword) 'No need to redeclare 'valid' here
    If valid Then
    ' Return the first AD server that successfully validates the credentials
    Return server.Trim()
    End If
    End Using
    Catch ex As Exception
    ' Log the exception or handle it (e.g., move to the next server)
    result = "ERROR: " + ViException.ErrorString(ex)
    End Try
    Next

    ' If no valid server is found, return Nothing
    Return Nothing

Children
No Data