It's been a long while since I've had to do this. ...
# lucee
t
It's been a long while since I've had to do this. Can anyone remind me how to generate the
encrypted:
version of a password for a datasource?
g
have a look at the source code, probably this, question is what BlowfishEasy is?
d
Quickest manual way: 1. Fire up a local Lucee Server with commandbox 2. Login to the Server Admin 3. Create a datasource with a name, user and password AND remove the "verify" at the bottom 4. Save the connection 5. fEdit that same datasource and the encrypted password should be at the bottom of the page in the connection info.
t
Somewhere along the way, someone gave me a commandbox method. The blowfish code looks familiar
Found it! Where's a commandbox function that works:
Copy code
function encryptDSpw(pass){		
        var salt = 'sdfsdfs';
        var cypher = createobject("java", "lucee.runtime.crypt.BlowfishEasy").init(salt);
		print.blueline( cypher.encryptString(arguments.pass) );
	}
d
Nice
b
I have a library already built on forgebox for this
It's what cfconfig uses
Just install it anf use
Called lucee password util I think
t
👍
It's definitely in commandbox, just couldn't find a way to call it
b
If you're already in CommandBox, like a Task, Runner, then you can just use the password util directly since CFConfig is already installed
t
What's the actual instruction though?
b
Copy code
CFSCRIPT-REPL: getInstance("PasswordManager@lucee-password-util").encryptDatasource( "myPass" )
c728b85e9c6ad60cb71f85cefcf9cf0f539f6a07321f8b0e
That's just me doing it in the REPL
you can get that same instance directly from wirebox via injection or whatever you need
and call the
encryptDatasource( "myPass" )
method on it
If you're passing it to Lucee, concat the text
encrypted:
to the start of the encrypted version so Lucee knows it's not coming in as plain text
This is what CFConfig does behind the scenes
And, of course
Copy code
CFSCRIPT-REPL: getInstance("PasswordManager@lucee-password-util").decryptDatasource( "c728b85e9c6ad60cb71f85cefcf9cf0f539f6a07321f8b0e" )
myPass
reverses it
t
I'm populating a .env so need the encrypted pass separately.
b
The Blowfish algorithm will create a different encrypted version every time, but they all decrypt to the same source text
I'm populating a .env so need the encrypted pass separately.
I'm not sure what this means?
Like, are you running commands from the CLI?
Code in a task runner?
package/server scripts?
t
I haven't automated the process yet, so I have a task runner that takes the raw pass and spits out the encrypted version
b
If you're just manually typing into an
.env
file in your project, then you can just use that code above in the REPL to to a one time encryption and then use the result
🙂 1
But if you wanted to build a custom command or even a task runner that accepts in a string and spits out the other version, then it would litearlly just be one line of code
Create a task with two targets
Something like
Copy code
component {
  property name="passwordManager" inject="PasswordManager@lucee-password-util";

  function encrypt(string pass ) {
    return passwordManager.encryptDatasource( pass  )     
  }

  function decrypt(string encryptedPass ) {
    return passwordManager.decryptDatasource( encryptedPass  )     
  }

}
And then call it as
Copy code
task run myTask encrypt myPass
task run myTask decrypt c728b85e9c6ad60cb71f85cefcf9cf0f539f6a07321f8b0e
Which you could prolly pair with
propertyFile set
like so
Copy code
propertFile set .env DB_PASSWORD `task run myTask encrypt myPass`
Or, if you really wanted, just make your task runners handle the property file writing as well
Our entire prop file DSL is available to you and easy to use https://commandbox.ortusbooks.com/task-runners/property-files#from-cfml
t
I'm definitely headed that way with the automation