Как определить мое шифрование AES 128 или 256? - PullRequest
0 голосов
/ 08 июля 2019

Добрый день,

У меня есть существующий класс Java AES-шифрования в моей рабочей области, однако я хотел бы знать, что он использует 128 или 256, я пытался найти его в Google, но все равно не смог его получить,следующий код:

static {
AesKeyCipher aesKeyCipher = new AesKeyCipher(
                        "747065a6cb23cacf3d4ae71edc929c678e8c15a50379b655b74a30eb77106d68" );
                cipher = aesKeyCipher;
}

public static String encrypt(final String saltText, final String plainText)
            throws UnsupportedEncodingException, GeneralSecurityException {
        final byte[] salt = saltText.getBytes( "UTF-8" );
        final byte[] plain = plainText.getBytes( "UTF-8" );

        for ( int i = 0; i < salt.length; i++ ) {
            if ( i >= plain.length ) {
                break;
            }
            plain[ i ] = (byte) ( salt[ i ] ^ plain[ i ] );
        }

        byte[] encrypted = cipher.encrypt( plain ); // this will call to the following encrypt method

        final String cipherText = new String(
                DatatypeConverter.printBase64Binary( encrypted ) );
        return cipherText;
    }


// this is the encrypt method call by first method
public byte[] encrypt(final byte[] data) throws GeneralSecurityException {
        try {
            final String currentTransform = "/ECB/NoPadding";
            final Cipher cipher = getCipher( currentTransform );
            final SecretKey secretKey = getSecretKey( );
            final AlgorithmParameterSpec params = getAlgorithmParameterSpec( );
            if ( params == null ) {
                cipher.init( Cipher.ENCRYPT_MODE, secretKey );
            } else {
                cipher.init( Cipher.ENCRYPT_MODE, secretKey, params );
            }
            return cipher.doFinal( data );
        } catch ( final GeneralSecurityException e ) {
            e.printStackTrace( );
            throw new EncryptionException( e );
        }
    }

А вот класс моего AesKeyCipher:

public class AesKeyCipher extends AbstractSecretKeyCipher implements
        SecretKeyCipher {

    @Override
    protected Cipher getCipher(String transform)
            throws GeneralSecurityException {
        return Cipher.getInstance( getSecretKey( ).getAlgorithm( ) );
    }

    @Override
    protected SecretKey getSecretKey() throws GeneralSecurityException {
        return new SecretKeySpec( hexStringToByteArray( this.key ), "AES" );
    }

    private static byte[] hexStringToByteArray(final String data) {
        int k = 0;
        byte[] results = new byte[data.length( ) / 2];
        for ( int i = 0; i + 1 < data.length( ); i += 2, k++ ) {
            results[ k ] = (byte) ( Character.digit( data.charAt( i ), 16 ) << 4 );
            results[ k ] += (byte) ( Character.digit( data.charAt( i + 1 ), 16 ) );
        }
        return results;
    }

}

Пожалуйста, посоветуйте, как его идентифицировать.

...