Skip to content

Commit

Permalink
Email settings can now be encrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
C4J committed Aug 5, 2024
1 parent 5d03cb6 commit b9ba77f
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 1 deletion.
36 changes: 35 additions & 1 deletion b6/commander4j.install4j
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<install4j version="10.0.8" transformSequenceNumber="10">
<directoryPresets config="./lib/db/auth" />
<directoryPresets config="./images/icons/CMD4j_Icons" />
<application name="Commander4j" applicationId="6923-0356-2321-8111" mediaDir="../../../Distribution/java17/b6Commander4j" shrinkRuntime="false" shortName="Commander4j" publisher="David Garratt" publisherWeb="http://www.commander4j.com" version="11.02" allPathsRelative="true" macVolumeId="2fff9a9d0dc659ac" javaMinVersion="17" javaMaxVersion="17">
<languages skipLanguageSelection="true">
<additionalLanguages>
Expand Down Expand Up @@ -304,6 +304,22 @@
<file path="./images/icons/CMD4j_Icons/MyIcon.iconset/icon_256x256.png" />
</iconImageFiles>
</launcher>
<launcher name="EncryptData" id="1313" icnsFile="./images/icons/CMD4j_Icons/MyIcon.icns">
<executable name="EncryptData" iconSet="true" iconFile="./images/icons/CMD4j_Icons/icon.ico" executableDir="." redirectStderr="false" executableMode="console" />
<java mainClass="com.commander4j.util.EncryptData">
<classPath>
<archive location="commander4j.jar" failOnError="false" />
<directory location="lib" failOnError="false" />
</classPath>
</java>
<iconImageFiles>
<file path="./images/icons/CMD4j_Icons/MyIcon.iconset/icon_16x16.png" />
<file path="./images/icons/CMD4j_Icons/MyIcon.iconset/icon_32x32.png" />
<file path="./images/icons/CMD4j_Icons/MyIcon.iconset/icon_48x48.png" />
<file path="./images/icons/CMD4j_Icons/MyIcon.iconset/icon_128x128.png" />
<file path="./images/icons/CMD4j_Icons/MyIcon.iconset/icon_256x256.png" />
</iconImageFiles>
</launcher>
</launchers>
<installerGui autoUpdateDescriptorUrl="${installer:C4JUpdaterUrl}">
<applications>
Expand Down Expand Up @@ -576,6 +592,24 @@ else
return false;
}</condition>
</action>
<action id="1314" beanClass="com.install4j.runtime.beans.actions.files.CopyFileAction" actionElevationType="elevated">
<serializedBean>
<property name="destinationFile">
<object class="java.io.File">
<string>xml/config</string>
</object>
</property>
<property name="files" type="array" class="java.io.File" length="1">
<element index="0">
<object class="java.io.File">
<string>${installer:sys.mediaDir}/email.xml</string>
</object>
</element>
</property>
<property name="overwriteMode" type="enum" class="com.install4j.api.context.OverwriteMode" value="ALWAYS" />
<property name="uninstallMode" type="enum" class="com.install4j.api.context.UninstallMode" value="NEVER" />
</serializedBean>
</action>
</actions>
<formComponents>
<formComponent id="873" beanClass="com.install4j.runtime.beans.formcomponents.ProgressComponent">
Expand Down
Binary file modified b6/commander4j.jar
Binary file not shown.
13 changes: 13 additions & 0 deletions b6/src/com/commander4j/email/SendEmail.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.commander4j.util.JUtility;
import com.commander4j.xml.JXMLDocument;
import com.commander4j.util.EncryptData;
import com.commander4j.util.JCipher;

import jakarta.mail.Authenticator;
import jakarta.mail.Message;
Expand All @@ -28,6 +30,7 @@ public class SendEmail
private boolean initialised = false;
private boolean enabled = false;
private String configID="";
private JCipher cipher = new JCipher(EncryptData.key);

public void init()
{
Expand All @@ -53,7 +56,17 @@ public void init()
{
String prop = doc.findXPath("/emailSettings/"+configID+"/property[" + String.valueOf(seq) + "]/@name").trim();
String val = doc.findXPath("/emailSettings/"+configID+"/property[" + String.valueOf(seq) + "]/@value").trim();
String encrypted = doc.findXPath("//configuration/property[" + String.valueOf(seq) + "]/@encrypted").trim().toLowerCase();

if (encrypted.equals(""))
{
encrypted = "no";
}

if (encrypted.equals("yes"))
{
val = cipher.decode(val);
}
if (prop.equals(""))
{
cont = false;
Expand Down
55 changes: 55 additions & 0 deletions b6/src/com/commander4j/util/EncryptData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.commander4j.util;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class EncryptData
{
public static String key = "wedkjh78687hgaFHDKqNKJGyfed;lkj<";

public static void main(String[] args)
{
// TODO Auto-generated method stub
System.out.println("Password Utility");
System.out.println("");
System.out.print("Input data to encrypt :");

Scanner in = new Scanner(System.in);

String s = in.nextLine();

in.close();

System.out.println("");
System.out.println("You entered [" + s+"]");
System.out.println("");

JCipher cipher = new JCipher(EncryptData.key);

String encrypted = cipher.encode(s);

try
{
FileWriter myWriter = new FileWriter("password.txt");

myWriter.write("Encrypted password is contained within the [ ] below.");
myWriter.write(System.lineSeparator());
myWriter.write(System.lineSeparator());
myWriter.write("Copy and paste into the sftpSend.xml to protect authentication passwords.");
myWriter.write(System.lineSeparator());
myWriter.write(System.lineSeparator());
myWriter.write("[" + encrypted + "]");
myWriter.write(System.lineSeparator());
myWriter.write(System.lineSeparator());
myWriter.flush();
myWriter.close();
System.out.println("Encrypted password saved to password.txt");
}
catch (IOException e)
{
System.out.println("Error :"+e.getMessage());
}
}

}
Loading

0 comments on commit b9ba77f

Please sign in to comment.