Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save maxcharlier/cae59d30e92df30a3586f621c8be55d5 to your computer and use it in GitHub Desktop.

Select an option

Save maxcharlier/cae59d30e92df30a3586f621c8be55d5 to your computer and use it in GitHub Desktop.

Revisions

  1. maxcharlier revised this gist Apr 20, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions dbVizPasswordDecrypt.groovy
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/usr/bin/env groovy

    import groovy.xml.*;
    import javax.crypto.SecretKeyFactory
    import javax.crypto.SecretKey
    import javax.crypto.Cipher
  2. @marcgeld marcgeld created this gist Jun 19, 2017.
    38 changes: 38 additions & 0 deletions dbVizPasswordDecrypt.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #!/usr/bin/env groovy

    import javax.crypto.SecretKeyFactory
    import javax.crypto.SecretKey
    import javax.crypto.Cipher
    import javax.crypto.spec.PBEParameterSpec
    import javax.crypto.spec.PBEKeySpec
    import java.util.Base64
    import java.util.Base64.Decoder
    import static java.nio.charset.StandardCharsets.UTF_8

    String password = "qinda"
    int iterations = 10
    // -114, 18, 57, -100, 7, 114, 111, 90]
    def salt = [ -114, 18, 57, -100, 7, 114, 111, 90] as byte[]

    PBEKeySpec keySpec = new PBEKeySpec( password.toCharArray() )
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "PBEWithMD5AndDES" )
    SecretKey key = keyFactory.generateSecret( keySpec )

    //Create parameters from the salt and an arbitrary number of iterations:
    PBEParameterSpec pbeParamSpec = new PBEParameterSpec( salt, iterations )
    Cipher cipher = Cipher.getInstance( "PBEWithMD5AndDES" )
    cipher.init( Cipher.DECRYPT_MODE, key, pbeParamSpec )

    Closure<String> decryptPw = { String encryptedPw ->
    byte[] decodedTmp = Base64.getDecoder().decode( encryptedPw )
    byte[] decryptedbytes = cipher.doFinal( decodedTmp )
    return new String ( decryptedbytes, UTF_8 )
    }

    def dbvis_config = "${System.getProperty('user.home')}/.dbvis/config70/dbvis.xml"

    def xml = new XmlSlurper().parse( dbvis_config )
    xml."Databases".children().each { node ->
    encryptedPassword = decryptPw( node.Password as String )
    println "'${node.Alias}', UserId: '${node.Userid}', Password: '${encryptedPassword}', url: '${node.Url}'"
    }