Announcement

Collapse
No announcement yet.

Mirth Appliance accessing MSSQL with Windows authentication

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I think I am ready to use .Net lol.

    function getEncryptedDBProperties(fname) {
    var Donkey = new Packages.com.mirth.connect.donkey.server.Donkey.ge tInstance();
    var sFilename = globalMap.get('globalPath') + "/conf/db/" + fname + ".properties";
    // Get LastADTCheck date/time
    var encryptor = Donkey.getEncryptor();
    var properties = new Packages.java.util.Properties();

    try {
    globalMap.put(fname +'.driver', properties.getProperty('driver'));
    globalMap.put(fname +'.db', properties.getProperty('db'));
    globalMap.put(fname +'.user', properties.getProperty('user'));
    globalMap.put(fname +'.pswd', encryptor.decrypt(properties.getProperty('pswd'))) ;

    } catch (err) {
    logger.error('ERROR getEncryptedDBProperties: ' + sFilename + ' not found.' + err.message);
    }

    }

    Comment


    • #17
      Naruply can you look at that code and possibly correct it?

      Comment


      • #18
        First, create a config file with your plaintext password. For example:

        Code:
        driver = org.postgresql.Driver
        db = postgres
        user = postgres
        pswd = postgres
        Then you need to encrypt it. This can be a one-off deploy script:

        Code:
        var props = org.apache.commons.configuration.PropertiesConfiguration(new java.io.File('appdata/dbconfig.properties'));
        var encryptor = com.mirth.connect.donkey.server.Donkey.getInstance().getEncryptor();
        props.setProperty('pswd', encryptor.encrypt(props.getProperty('pswd')));
        props.save();
        Now the file looks like:

        Code:
        driver = org.postgresql.Driver
        db = postgres
        user = postgres
        pswd = a24m7kKlLI3/4nWRSVnepA==\r\n
        At this point you can get rid of the deploy script and/or channel, since you only needed it to encrypt that password. Now you can load the properties into the global map in the global deploy script:

        Code:
        var props = org.apache.commons.configuration.PropertiesConfiguration(new java.io.File('appdata/dbconfig.properties'));
        var encryptor = com.mirth.connect.donkey.server.Donkey.getInstance().getEncryptor();
        
        for (var it = props.getKeys(); it.hasNext();) {
        	var key = it.next();
        	var value = props.getProperty(key);
        
        	if (key == 'pswd') {
        		value = encryptor.decrypt(value);
        	}
        
        	$g(key, value);
        }
        Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

        Nicholas Rupley
        Work: 949-237-6069
        Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


        - How do I foo?
        - You just bar.

        Comment


        • #19
          Works great!! you are the man. Thank you.

          Comment


          • #20
            com.mirth.commons.encryption.EncryptionException: javax.crypto.BadPaddingException: p

            I am getting these errors now. What can cause this using that same code?

            com.mirth.commons.encryption.EncryptionException: javax.crypto.BadPaddingException: pad block corrupted

            Comment


            • #21
              Has anyone ever seen this error?

              Comment

              Working...
              X