Skip to content

Instantly share code, notes, and snippets.

@marcgeld
Created June 19, 2017 11:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save marcgeld/e484fe918d8cc14358edadd3f3ad3295 to your computer and use it in GitHub Desktop.
Save marcgeld/e484fe918d8cc14358edadd3f3ad3295 to your computer and use it in GitHub Desktop.
Decode DbVisualizer settings password. (https://www.dbvis.com/)
#!/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}'"
}
@srinivas-os
Copy link

Works with DbVis v11.0.3. Thank you!

@marcgeld
Copy link
Author

Yes, it is quite useful. Thanks for confirming it works with newer versions of DbVis.

@Petracchi1
Copy link

I'm happy to report that it also works with DbVis v12.0.7 on macOS Catalina (v10.15.7). Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment