Skip to content

rikcarve/security

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Java Security 1x1

Keytool

keytool -importpass -storetype pkcs12 -alias myentry -keystore password-store.p12
keytool -list -keystore password-store.p12 -storetype pkcs12

Elytron

/subsystem=elytron/credential-store=mycs:add(relative-to=jboss.server.data.dir, location=example.jceks,create=true,credential-reference={clear-text=mypwd})
/subsystem=elytron/credential-store=mycs:add-alias(alias=myEntry,secret-value=mysecretpwd)
/subsystem=elytron/credential-store=mycs:read-aliases()
                <credential-store name="cs12" relative-to="jboss.server.data.dir" location="password-store.p12" create="true">
                    <implementation-properties>
                        <property name="keyStoreType" value="PKCS12"/>
                    </implementation-properties>
                    <credential-reference clear-text="MASK-Bmfq4mvDV7F;A1B2C3D4;351"/>
                </credential-store>
elytron-tool.bat mask -i 351 -s A1B2C3D4 -x mypwd

Use elytron in datasource

                <datasource jndi-name="java:/jdbc/myDS" pool-name="MySqlDS">
                    <connection-url>jdbc:mysql:https://localhost:3306/test</connection-url>
                    <driver>mysql</driver>
                    <security>
                        <user-name>rik</user-name>
                        <credential-reference store="cs12" alias="dbpwd"/>
                    </security>

Java code

    public static void main(String[] args) throws Exception {
        KeyStore keyStore = KeyStore.getInstance("pkcs12");
        char[] pwdArray = "mypwd".toCharArray();
        keyStore.load(new FileInputStream("password-store.p12"), pwdArray);
        SecretKeyEntry ske = (SecretKeyEntry) keyStore.getEntry("myentry", new KeyStore.PasswordProtection(pwdArray));       
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
        PBEKeySpec keySpec = (PBEKeySpec)factory.getKeySpec(ske.getSecretKey(), PBEKeySpec.class);
        System.out.println(new String(keySpec.getPassword()));
    }

About

Java Security 1x1 - keytool, elytron, java

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published