Class KeyFactoryTest


  • public class KeyFactoryTest
    extends java.lang.Object
    This test class can be used to validate a KeyFactory low-level implementation.

    Currently, only the ECPublicKeyNamedCurveSpec parameter is tested.

    • Constructor Detail

      • KeyFactoryTest

        public KeyFactoryTest()
    • Method Detail

      • testExportPrivateKeyToPkcs8

        public void testExportPrivateKeyToPkcs8()
                                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testGeneratePublicKeyFromECNamedCurveAndAffineCoordinates

        public void testGeneratePublicKeyFromECNamedCurveAndAffineCoordinates()
                                                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testGeneratePrivateRejectsInvalidEncoding

        public void testGeneratePrivateRejectsInvalidEncoding()
                                                       throws java.lang.Exception
        Encoded private key bytes the backend cannot decode are reported with the checked exception the JCA declares, not with a runtime exception an Application following the JCA contract would not catch.
        Throws:
        java.lang.Exception
      • testGeneratePublicRejectsInvalidEncoding

        public void testGeneratePublicRejectsInvalidEncoding()
                                                      throws java.lang.Exception
        Encoded public key bytes the backend cannot decode are reported with the checked exception the JCA declares.
        Throws:
        java.lang.Exception
      • testGeneratePublicRejectsUnknownCurve

        public void testGeneratePublicRejectsUnknownCurve()
                                                   throws java.lang.Exception
        A named-curve public key spec the backend cannot use is reported with the checked exception the JCA declares.

        An unknown curve name is used rather than coordinates off the curve: not every backend checks that the point lies on the curve when importing it.

        Throws:
        java.lang.Exception
      • testPrivateKeyGetEncodedReturnsDefensiveCopy

        public void testPrivateKeyGetEncodedReturnsDefensiveCopy()
                                                          throws java.lang.Exception
        Verifies that the PrivateKey returned by a KeyFactory hands back a fresh defensive copy from Key.getEncoded() on every call, so a caller that mutates the returned array cannot corrupt the key's cached encoding.
        Throws:
        java.lang.Exception
      • testPublicKeyGetEncodedReturnsDefensiveCopy

        public void testPublicKeyGetEncodedReturnsDefensiveCopy()
                                                         throws java.lang.Exception
        Verifies that the PublicKey returned by a KeyFactory hands back a fresh defensive copy from Key.getEncoded() on every call, so a caller that mutates the returned array cannot corrupt the key's cached encoding.
        Throws:
        java.lang.Exception