JavaBlog.fr / Java.lu DEVELOPMENT,DFC DCTM,Documentum,Java Documentum, Java: Encrypt/Decrypt dfc.properties password

Documentum, Java: Encrypt/Decrypt dfc.properties password

Hello,

I would like to present a solution in order to encrypt/decrypt the passwords of registry for example the password in the dfc.properties via Java programming with the following Documentum utilities classes:

1com.documentum.fc.tools.RegistryPasswordUtils.encrypt("password to be encrypted") ;
2com.documentum.fc.tools.RegistryPasswordUtils.decrypt ("password to be decrypted") ;

Dfc.properties

1dfc.globalregistry.repository=globalr
2dfc.globalregistry.username=dm_bof_registry
3dfc.globalregistry.password=XXXXXfsfezrezxxxxxrezrzrXXX/0ezxxxxxxIGAL

 
To encrypt/decrypt this value via JAVA programming:

  1. Java decrypting method:
    01/**
    02 * Decrypting with BOF utils - shorter, base64 encoded passwords
    03 *
    04 * @param passwordEncrypted
    05 * @return
    06 */
    07public static String decryptWithBOFUtils(String passwordEncrypted) {
    08    String ret = null;
    09    try {
    10        System.out.print("\tBOF Utils (decrypt) -> " + passwordEncrypted + "\t\t\t\t");
    11        ret = com.documentum.fc.tools.RegistryPasswordUtils.decrypt(passwordEncrypted);
    12    } catch (Exception e) {
    13        System.out.println("ERROR: " + e.getMessage());
    14    }
    15    return ret;
    16}

     

  2. Java encrypting method:
    01/**
    02 * Encrypting with BOF utils - shorter, base64 encoded passwords
    03 *
    04 * @param passwordToEncrypt
    05 * @return
    06 */
    07public static String encryptWithBOFUtils(String passwordToEncrypt) {
    08    String ret = null;
    09    try {
    10        System.out.print("\tBOF Utils (encrypt) -> " + passwordToEncrypt+ "\t\t\t\t");
    11        ret = com.documentum.fc.tools.RegistryPasswordUtils.encrypt(passwordToEncrypt);
    12    } catch (Exception e) {
    13        System.out.println("ERROR: " + e.getMessage());
    14    }
    15    return ret;
    16}

     

  3. Test decrypting and encrypting method:
    01// --------------------------------- Encrypting/Decrypting with BOF utils
    02String password = null;
    03String clearText = null;
    04                         
    05password = "XXXXXfsfezrezxxxxxrezrzrXXX/0ezxxxxxxIGAL";
    06// try decrypting with BOF utils - shorter, base64 encoded passwords
    07System.out.println("\nTrying to decrypt '" + password + "'...\n");
    08clearText = decryptWithBOFUtils(password);
    09if ((clearText != null) && (clearText.length() > 0)) {
    10    System.out.println("'" + clearText + "'");
    11}else{
    12    System.exit(1);
    13}
    14             
    15clearText = "TEST-javablog-Documentum@123";
    16             
    17// try decrypting with BOF utils - shorter, base64 encoded passwords
    18System.out.println("\nTrying to encrypt '" + clearText + "'...\n");
    19password = encryptWithBOFUtils(clearText);
    20if ((password != null) && (password.length() > 0)) {
    21    System.out.println("'" + password + "'");
    22}else{
    23    System.exit(1);
    24}
    25             
    26// try decrypting with BOF utils - shorter, base64 encoded passwords
    27System.out.println("\nTrying to decrypt again '" + password + "'...\n");
    28clearText = decryptWithBOFUtils(password);
    29if ((clearText != null) && (clearText.length() > 0)) {
    30    System.out.println("'" + clearText + "'");
    31}else{
    32    System.exit(1);
    33}

     

 
 
Here, a code found to decrypt BOF and database passwords (https://www.snip2code.com/Snippet/242104/Decrypt-Documentum-database-passwords-) :

001/*
002 * (C) 2012 MSRoth - msroth.wordpress.com
003 *
004 * recoverPW v2
005 *
006 * This code will decrypt BOF and database passwords.  It will *NOT* decrypt inline user passwords.
007 *
008 * From the D6.5 EMC Documentum Content Server Administration Guide, p. 353:
009 * "Passwords encrypted with encryptPassword cannot be decrypted explicitly
010 * by an application or user."
011 *
012 * usage:  c:>java recoverPW <password>
013 *
014 * aek.key file must exist in c:\documentum\config
015 *
016 */
017 
018package com.dm_misc.recoverpw;
019 
020import com.documentum.fc.client.impl.crypto.CryptoUtils;
021import com.documentum.fc.tools.RegistryPasswordUtils;
022import com.documentum.dmcl.impl.DmclApi;
023import com.documentum.web.formext.session.TrustedAuthenticatorTool;
024import com.documentum.web.formext.session.TrustedAuthenticatorUtils;
025import java.io.*;
026 
027public class RecoverPW {
028 
029    private static final String AEK_PATH = "c:/documentum/config/aek.key";
030    private static boolean decrypted = false;
031    private static String password = "";
032 
033    public static void main(String args[]) {
034 
035        try {
036            if (args.length != 1) {
037                System.out.println("usage: c:>java recoverPW <password>");
038                System.exit(1);
039            }
040 
041            File file = new File(AEK_PATH);
042            if (!file.exists()) {
043                System.out.println("Could not find aek.key file.  Please copy from Content Server to " + AEK_PATH);
044                System.exit(1);
045            }
046 
047            // get encrypted password from command line
048            password = args[0];
049            System.out.println("\nTrying to decrypt '" + password + "'...\n");
050 
051            // try decrypting with BOF utils - shorter, base64 encoded passwords
052            try {
053                String clearText = "";
054                System.out.print("\tBOF Utils ->\t\t\t\t");
055                clearText = RegistryPasswordUtils.decrypt(password);
056                if ((clearText != null) && (clearText.length() > 0)) {
057                    System.out.println("'" + clearText + "'");
058                    decrypted = true;
059                }
060 
061            } catch (Exception e) {
062                System.out.println("ERROR: " + e.getMessage());
063            }
064 
065            // try decrypting with API - longer, dm_encrypt_password passwords
066            try {
067                String clearText = "";
068                System.out.print("\tAPI ->\t\t\t\t\t");
069                DmclApi.getInstance().exec("initcrypto,c," + AEK_PATH);
070                clearText = DmclApi.getInstance().get("decrypttext,c,DM_ENCR_TEXT=" + password);
071                if ((clearText != null) && (clearText.length() > 0)) {
072                    System.out.println("'" + clearText + "'");
073                    decrypted = true;
074                }
075 
076            } catch (Exception e) {
077                System.out.println("ERROR: " + e.getMessage());
078            }
079 
080            // try decrypting with CryptoUtils(Password)
081            try {
082                String clearText = "";
083                System.out.print("\tCryptoUtils (password) ->\t\t");
084                CryptoUtils c = CryptoUtils.getInstance();
085                clearText = c.decryptPassword("DM_ENCR_PASS=" + password);
086                if ((clearText != null) && (clearText.length() > 0)) {
087                    System.out.println("'" + clearText + "'");
088                    decrypted = true;
089                }
090 
091            } catch (Exception e) {
092                System.out.println("ERROR: " + e.getMessage());
093            }
094 
095            // try decrypting with CryptoUtils(Text)
096            try {
097                String clearText = "";
098                System.out.print("\tCryptoUtils (text) ->\t\t\t");
099                CryptoUtils c = CryptoUtils.getInstance();
100                clearText = c.decryptText("DM_ENCR_TEXT=" + password, "p6lo3ly1oj5ne&");
101                if ((clearText != null) && (clearText.length() > 0)) {
102                    System.out.println("'" + clearText + "'");
103                    decrypted = true;
104                }
105 
106            } catch (Exception e) {
107                System.out.println("ERROR: " + e.getMessage());
108            }
109 
110            // try WDK DES
111            try {
112                String clearText = "";
113                System.out.print("\tTrustedAuthenticatorUtils (DES) ->\t");
114                clearText = TrustedAuthenticatorUtils.decryptByDES(password);
115                if ((clearText != null) && (clearText.length() > 0)) {
116                    System.out.println("'" + clearText + "'");
117                    decrypted = true;
118                }
119 
120            } catch (Exception e) {
121                System.out.println("ERROR: " + e.getMessage());
122            }
123 
124            // try WDK decrypt
125            try {
126                String clearText = "";
127                System.out.print("\tTrustedAuthenticatorUtils (decrypt) ->\t");
128                clearText = TrustedAuthenticatorUtils.decrypt(password);
129                if ((clearText != null) && (clearText.length() > 0)) {
130                    System.out.println("'" + clearText + "'");
131                    decrypted = true;
132                }
133 
134            } catch (Exception e) {
135                System.out.println("ERROR: " + e.getMessage());
136            }
137 
138            // try WDK Authenticator Tool - just uses TrustedAuthenticatorUtils to encrypt
139            // This will never decrypt, running the main() only does encrypt.
140            try {
141                System.out.print("\tWDK authenticator tool -> \t\t");
142 
143                // create a stream to hold the output since WDK authenticator tool
144                // prints to console
145                ByteArrayOutputStream baos = new ByteArrayOutputStream();
146                PrintStream ps = new PrintStream(baos);
147                PrintStream old = System.out;
148                System.setOut(ps);
149 
150                // call tool to decrypt text
151                TrustedAuthenticatorTool.main(new String[]{password});
152 
153                // put things back
154                System.out.flush();
155                System.setOut(old);
156 
157                // see what happened
158                String clearText = baos.toString();
159                int idx = clearText.indexOf("Decrypted:");
160                if (idx > 0) {
161                    clearText = clearText.substring(idx + "Decrypted: [".length(), clearText.length() - 3);
162                    System.out.println("'" + clearText + "'");
163                    if (clearText.equalsIgnoreCase(password)) {
164                        decrypted = false;
165                    } else {
166                        decrypted = true;
167                    }
168                } else {
169                    System.out.println("ERROR: could not decrypt with WDK Authenticator Tool");
170                }
171 
172            } catch (Exception e) {
173                System.out.println("ERROR: " + e.getMessage());
174            }
175 
176        } catch (Exception e) {
177            System.out.println("General Error: " + e.getMessage());
178        }
179 
180        System.out.println();
181        if (!decrypted) {
182            System.out.println("\nSorry, could not decrypt '" + password + "'.");
183        }
184        System.out.println("Done.");
185    }
186}

 

That’s all!!!

Huseyin OZVEREN

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

Related Post