Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ target/
.classpath
.settings/
bin
*.iml

44 changes: 25 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>plexus-cipher</artifactId>
<version>1.9-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>

<name>Plexus Cipher: encryption/decryption Component</name>

Expand All @@ -32,16 +32,37 @@

<properties>
<javaVersion>7</javaVersion>
<sisuVersion>0.3.4</sisuVersion>
<project.build.outputTimestamp>2020-01-20T18:52:37Z</project.build.outputTimestamp>
</properties>


<dependencies>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.inject</artifactId>
<version>${sisuVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
Expand Down Expand Up @@ -106,7 +127,7 @@
<plugin>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
<version>0.3.4</version>
<version>${sisuVersion}</version>
<executions>
<execution>
<goals>
Expand All @@ -119,19 +140,4 @@
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-bean</artifactId>
<version>2.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class Base64
* The value of undefined encodings is <code>-1</code>.
* </p>
*/
private static byte[] base64Alphabet = new byte[BASELENGTH];
private static final byte[] base64Alphabet = new byte[BASELENGTH];

/**
* <p/>
Expand All @@ -110,7 +110,7 @@ public class Base64
* For example, <code>lookUpBase64Alphabet[62] </code> returns <code>'+'</code>.
* </p>
*/
private static byte[] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];
private static final byte[] lookUpBase64Alphabet = new byte[LOOKUPLENGTH];

// Populating the lookup and character arrays
static {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2008 Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
Expand All @@ -15,14 +15,14 @@
import java.security.Provider;
import java.security.Security;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.enterprise.inject.Typed;
import javax.inject.Named;

import org.eclipse.sisu.Typed;

/**
* @author Oleg Gusakov
*/
Expand Down Expand Up @@ -136,61 +136,54 @@ public String decorate( final String str )
*/
public static String[] getServiceTypes()
{
Set result = new HashSet();
Set<String> result = new HashSet<>();

// All all providers
Provider[] providers = Security.getProviders();
for ( int i = 0; i < providers.length; i++ )
{
for (Provider provider : providers) {
// Get services provided by each provider
Set keys = providers[i].keySet();
for ( Iterator it = keys.iterator(); it.hasNext(); )
{
String key = (String) it.next();
key = key.split( " " )[0];

if ( key.startsWith( "Alg.Alias." ) )
{
Set<Object> keys = provider.keySet();
for (Object o : keys) {
String key = (String) o;
key = key.split(" ")[0];

if (key.startsWith("Alg.Alias.")) {
// Strip the alias
key = key.substring( 10 );
key = key.substring(10);
}
int ix = key.indexOf( '.' );
result.add( key.substring( 0, ix ) );
int ix = key.indexOf('.');
result.add(key.substring(0, ix));
}
}
return (String[]) result.toArray( new String[result.size()] );
return result.toArray( new String[result.size()] );
}

/**
* This method returns the available implementations for a service type
*/
public static String[] getCryptoImpls( final String serviceType )
{
Set result = new HashSet();
Set<String> result = new HashSet<>();

// All all providers
Provider[] providers = Security.getProviders();
for ( int i = 0; i < providers.length; i++ )
{
for (Provider provider : providers) {
// Get services provided by each provider
Set keys = providers[i].keySet();
for ( Iterator it = keys.iterator(); it.hasNext(); )
{
String key = (String) it.next();
key = key.split( " " )[0];

if ( key.startsWith( serviceType + "." ) )
{
result.add( key.substring( serviceType.length() + 1 ) );
Set<Object> keys = provider.keySet();
for (Object o : keys) {
String key = (String) o;
key = key.split(" ")[0];

if (key.startsWith(serviceType + ".")) {
result.add(key.substring(serviceType.length() + 1));
}
else if ( key.startsWith( "Alg.Alias." + serviceType + "." ) )
{
else if (key.startsWith("Alg.Alias." + serviceType + ".")) {
// This is an alias
result.add( key.substring( serviceType.length() + 11 ) );
result.add(key.substring(serviceType.length() + 11));
}
}
}
return (String[]) result.toArray( new String[result.size()] );
return result.toArray( new String[result.size()] );
}

// ---------------------------------------------------------------
Expand All @@ -201,26 +194,18 @@ public static void main( final String[] args )
String[] serviceTypes = getServiceTypes();
if ( serviceTypes != null )
{
for ( int i = 0; i < serviceTypes.length; i++ )
{
String serviceType = serviceTypes[i];
String[] serviceProviders = getCryptoImpls( serviceType );
if ( serviceProviders != null )
{
System.out.println( serviceType + ": provider list" );
for ( int j = 0; j < serviceProviders.length; j++ )
{
String provider = serviceProviders[j];
System.out.println( " " + provider );
for (String serviceType : serviceTypes) {
String[] serviceProviders = getCryptoImpls(serviceType);
if (serviceProviders != null) {
System.out.println(serviceType + ": provider list");
for (String provider : serviceProviders) {
System.out.println(" " + provider);
}
}
else
{
System.out.println( serviceType + ": does not have any providers in this environment" );
else {
System.out.println(serviceType + ": does not have any providers in this environment");
}
}
}
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* createCipher routine was adopted from http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.10/src/java/org/apache/commons/ssl/OpenSSL.java
* which is distributed under APL-2.0 license: http://www.apache.org/licenses/LICENSE-2.0
*/
Expand Down Expand Up @@ -58,7 +58,7 @@ public class PBECipher

protected static final String CIPHER_ALG = "AES/CBC/PKCS5Padding";

protected static int PBE_ITERATIONS = 1000;
protected static final int PBE_ITERATIONS = 1000;

protected MessageDigest _digester;

Expand Down Expand Up @@ -234,6 +234,4 @@ private Cipher createCipher( final byte [] pwdAsBytes, byte [] salt, final int m

return cipher;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2008 Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
Expand All @@ -17,16 +17,16 @@
*/
public interface PlexusCipher
{
public static final char ENCRYPTED_STRING_DECORATION_START = '{';
char ENCRYPTED_STRING_DECORATION_START = '{';

public static final char ENCRYPTED_STRING_DECORATION_STOP = '}';
char ENCRYPTED_STRING_DECORATION_STOP = '}';

/**
* encrypt given string with the given passPhrase and encode it into base64
*
* @param str
* @param passPhrase
* @return
* @return encrypted str
* @throws PlexusCipherException
*/
String encrypt( String str, String passPhrase )
Expand All @@ -38,7 +38,7 @@ String encrypt( String str, String passPhrase )
*
* @param str
* @param passPhrase
* @return
* @return encrypted and decorated str
* @throws PlexusCipherException
*/
String encryptAndDecorate( String str, String passPhrase )
Expand All @@ -49,7 +49,7 @@ String encryptAndDecorate( String str, String passPhrase )
*
* @param str
* @param passPhrase
* @return
* @return decrypted str
* @throws PlexusCipherException
*/
String decrypt( String str, String passPhrase )
Expand All @@ -61,7 +61,7 @@ String decrypt( String str, String passPhrase )
*
* @param str
* @param passPhrase
* @return
* @return decrypted decorated str
* @throws PlexusCipherException
*/
String decryptDecorated( String str, String passPhrase )
Expand All @@ -71,26 +71,25 @@ String decryptDecorated( String str, String passPhrase )
* check if given string is decorated
*
* @param str
* @return
* @return true if string is encrypted
*/
public boolean isEncryptedString( String str );
boolean isEncryptedString( String str );

/**
* return string inside decorations
*
* @param str
* @return
* @return undecorated str
* @throws PlexusCipherException
*/
public String unDecorate( String str )
String unDecorate( String str )
throws PlexusCipherException;

/**
* decorated given string with { and }
*
* @param str
* @return
* @return decorated str
*/
public String decorate( String str );

String decorate( String str );
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (c) 2008 Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
Expand All @@ -15,7 +15,6 @@
public class PlexusCipherException
extends Exception
{

public PlexusCipherException()
{
}
Expand All @@ -34,5 +33,4 @@ public PlexusCipherException( String message, Throwable cause )
{
super( message, cause );
}

}
12 changes: 0 additions & 12 deletions src/main/resources/META-INF/plexus/components.xml

This file was deleted.

Loading