Class RSACipherTest


  • public class RSACipherTest
    extends java.lang.Object
    • Constructor Detail

      • RSACipherTest

        public RSACipherTest()
    • Method Detail

      • loadKeyPairs

        public static void loadKeyPairs()
                                 throws java.lang.Exception
        Loads the RSA key pair of every configured key size from the test material, so that the class measures the cipher only and runs on a backend without key pair generation.
        Throws:
        java.lang.Exception - if a key cannot be loaded
      • testRSA_PKCS1Padding_SinglePart_1byte

        public void testRSA_PKCS1Padding_SinglePart_1byte()
                                                   throws java.lang.Exception
        Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing 1 byte of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_PKCS1Padding_SinglePart_16bytes

        public void testRSA_PKCS1Padding_SinglePart_16bytes()
                                                     throws java.lang.Exception
        Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing 16 bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_PKCS1Padding_MultiPart_16bytes

        public void testRSA_PKCS1Padding_MultiPart_16bytes()
                                                    throws java.lang.Exception
        Test the "RSA/ECB/PKCS1Padding" cipher with a multi-part operation containing 16 bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_PKCS1Padding_SinglePart_maxBytes

        public void testRSA_PKCS1Padding_SinglePart_maxBytes()
                                                      throws java.lang.Exception
        Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing max bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_PKCS1Padding_SinglePart_lengthError

        public void testRSA_PKCS1Padding_SinglePart_lengthError()
                                                         throws java.lang.Exception
        Test the "RSA/ECB/PKCS1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testCipherAtNonZeroOffsets

        public void testCipherAtNonZeroOffsets()
                                        throws java.lang.Exception
        Encrypting from a sub-range into an offset and decrypting back from a sub-range into an offset round-trip the message for every configured key size, without touching the bytes around either result.

        An output short by exactly the offset is refused rather than overrun: an implementation computing its capacity from the array length rather than from the length past the offset finds room that is not there.

        Neither offset reaches the backend: the RSA cipher buffers its input and copies its result into place itself, so this case checks the library.

        Throws:
        java.lang.Exception
      • testDecryptRejectsTamperedCiphertext

        public void testDecryptRejectsTamperedCiphertext()
                                                  throws java.lang.Exception
        A ciphertext whose bytes were altered does not decrypt, and the failure is the BadPaddingException that Cipher.doFinal(byte[]) declares. The library raises it only for the error code the abstraction layer declares for a failed decryption, not for a backend failure.

        A ciphertext is the part of an exchange an attacker reaches, so a caller has to be able to tell "this message is not for me, or was altered" from "the backend broke", and nothing asserted that distinction before.

        Throws:
        java.lang.Exception - if the encryption fails
      • testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_1byte

        public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_1byte()
                                                                 throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing 1 byte of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_16bytes

        public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_16bytes()
                                                                   throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing 16 bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA1AndMGF1Padding_MultiPart_16bytes

        public void testRSA_OAEPWithSHA1AndMGF1Padding_MultiPart_16bytes()
                                                                  throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a multi-part operation containing 16 bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_maxBytes

        public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_maxBytes()
                                                                    throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing max bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_lengthError

        public void testRSA_OAEPWithSHA1AndMGF1Padding_SinglePart_lengthError()
                                                                       throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-1AndMGF1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_1byte

        public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_1byte()
                                                                   throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing 1 byte of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_16bytes

        public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_16bytes()
                                                                     throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing 16 bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA256AndMGF1Padding_MultiPart_16bytes

        public void testRSA_OAEPWithSHA256AndMGF1Padding_MultiPart_16bytes()
                                                                    throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a multi-part operation containing 16 bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_maxBytes

        public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_maxBytes()
                                                                      throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing max bytes of input data.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_lengthError

        public void testRSA_OAEPWithSHA256AndMGF1Padding_SinglePart_lengthError()
                                                                         throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" cipher with a single-part operation containing a big input data that is expected to throw an exception.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.
      • testRSA_OAEP_params

        public void testRSA_OAEP_params()
                                 throws java.lang.Exception
        Test the "RSA/ECB/OAEPWithdigestAndMGF1Padding" cipher with a single-part operation containing 1 byte of input data and explicit OAEP encryption parameters.
        Throws:
        java.lang.Exception - if the encryption or decryption fails.