24 package org.lightjason.agentspeak.action.builtin.crypto;
26 import org.apache.commons.lang3.tuple.ImmutablePair;
27 import org.apache.commons.lang3.tuple.Pair;
31 import javax.annotation.Nonnull;
32 import javax.crypto.Cipher;
33 import javax.crypto.KeyGenerator;
34 import javax.crypto.NoSuchPaddingException;
35 import java.security.InvalidKeyException;
36 import java.security.Key;
37 import java.security.KeyPair;
38 import java.security.KeyPairGenerator;
39 import java.security.NoSuchAlgorithmException;
40 import java.util.Locale;
48 AES(
"AES/ECB/PKCS5Padding",
"AES" ),
49 DES(
"DES/ECB/PKCS5Padding",
"DES" ),
50 RSA(
"RSA/ECB/PKCS1Padding",
"RSA" );
67 EAlgorithm( @Nonnull
final String p_cipher, @Nonnull
final String p_key )
81 public final Pair<Key, Key>
generateKey() throws NoSuchAlgorithmException
87 return new ImmutablePair<>( KeyGenerator.getInstance( m_key ).generateKey(), null );
90 final KeyPair l_key = KeyPairGenerator.getInstance( m_key ).generateKeyPair();
91 return new ImmutablePair<>( l_key.getPublic(), l_key.getPrivate() );
109 public final Cipher
getEncryptCipher( @Nonnull
final Key p_key )
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException
111 final Cipher l_cipher = Cipher.getInstance( m_cipher );
112 l_cipher.init( Cipher.ENCRYPT_MODE, p_key );
127 public final Cipher
getDecryptCipher( @Nonnull
final Key p_key )
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException
129 final Cipher l_cipher = Cipher.getInstance( m_cipher );
130 l_cipher.init( Cipher.DECRYPT_MODE, p_key );
143 return EAlgorithm.valueOf( p_value.trim().toUpperCase( Locale.ROOT ) );
final Cipher getDecryptCipher( @Nonnull final Key p_key)
final String m_key
key name
final Cipher getEncryptCipher( @Nonnull final Key p_key)
returns encrypt cipher
final String m_cipher
chipher name
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
static EAlgorithm from( @Nonnull final String p_value)
additional factory
enum with encrypting types
EAlgorithm( @Nonnull final String p_cipher, @Nonnull final String p_key)
ctor
final Pair< Key, Key > generateKey()
generates a key
class for any helper calls