com.ibm.crypto.fips.provider

Class RSACipher

  • java.lang.Object
    • javax.crypto.CipherSpi
      • com.ibm.crypto.fips.provider.RSACipher


  • public final class RSACipher
    extends javax.crypto.CipherSpi
    RSA cipher implementation. Supports RSA en/decryption and signing/verifying using PKCS#1 v1.5 padding and without padding (raw RSA). Note that raw RSA is supported mostly for completeness and should only be used in rare cases. Objects should be instantiated by calling Cipher.getInstance() using the following algorithm names: . "RSA/ECB/PKCS1Padding" (or "RSA") for PKCS#1 padding. The mode (blocktype) is selected based on the en/decryption mode and public/private key used . "RSA/ECB/NoPadding" for rsa RSA. We only do one RSA operation per doFinal() call. If the application passes more data via calls to update() or doFinal(), we throw an IllegalBlockSizeException when doFinal() is called (see JCE API spec). Bulk encryption using RSA does not make sense and is not standardized. Note: RSA keys should be at least 512 bits long
    Since:
    1.5
    • Constructor Summary

      Constructors 
      Constructor and Description
      RSACipher()
      Verify the JCE framework in the constructor.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      protected byte[] engineDoFinal(byte[] in, int inOfs, int inLen) 
      protected int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) 
      protected int engineGetBlockSize() 
      protected byte[] engineGetIV() 
      protected int engineGetKeySize(java.security.Key key) 
      protected int engineGetOutputSize(int inputLen) 
      protected java.security.AlgorithmParameters engineGetParameters() 
      protected void engineInit(int opmode, java.security.Key key, java.security.spec.AlgorithmParameterSpec params, java.security.SecureRandom random) 
      protected void engineInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random) 
      protected void engineInit(int opmode, java.security.Key key, java.security.SecureRandom random) 
      protected void engineSetMode(java.lang.String mode) 
      protected void engineSetPadding(java.lang.String paddingName) 
      protected java.security.Key engineUnwrap(byte[] wrappedKey, java.lang.String algorithm, int type) 
      protected byte[] engineUpdate(byte[] in, int inOfs, int inLen) 
      protected int engineUpdate(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) 
      protected byte[] engineWrap(java.security.Key key) 
      protected byte[] internalDoFinal(byte[] in, int inOfs, int inLen) 
      protected int internalDoFinal(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) 
      protected int internalGetBlockSize() 
      protected byte[] internalGetIV() 
      protected int internalGetKeySize(java.security.Key key) 
      protected int internalGetOutputSize(int inputLen) 
      protected java.security.AlgorithmParameters internalGetParameters() 
      protected void internalInit(int opmode, java.security.Key key, java.security.AlgorithmParameters params, java.security.SecureRandom random) 
      protected void internalInit(int opmode, java.security.Key key, java.security.SecureRandom random) 
      protected void internalSetMode(java.lang.String mode) 
      protected void internalSetPadding(java.lang.String paddingName) 
      protected java.security.Key internalUnwrap(byte[] wrappedKey, java.lang.String algorithm, int type) 
      protected byte[] internalUpdate(byte[] in, int inOfs, int inLen) 
      protected int internalUpdate(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) 
      protected byte[] internalWrap(java.security.Key key) 
      • Methods inherited from class javax.crypto.CipherSpi

        engineDoFinal, engineUpdate, engineUpdateAAD, engineUpdateAAD
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RSACipher

        public RSACipher()
        Verify the JCE framework in the constructor.
        Throws:
        java.lang.SecurityException - if fails to verify the JCE framework.
    • Method Detail

      • engineSetMode

        protected void engineSetMode(java.lang.String mode)
                              throws java.security.NoSuchAlgorithmException
        Specified by:
        engineSetMode in class javax.crypto.CipherSpi
        Throws:
        java.security.NoSuchAlgorithmException
      • internalSetMode

        protected void internalSetMode(java.lang.String mode)
                                throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • engineSetPadding

        protected void engineSetPadding(java.lang.String paddingName)
                                 throws javax.crypto.NoSuchPaddingException
        Specified by:
        engineSetPadding in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.NoSuchPaddingException
      • internalSetPadding

        protected void internalSetPadding(java.lang.String paddingName)
                                   throws javax.crypto.NoSuchPaddingException
        Throws:
        javax.crypto.NoSuchPaddingException
      • engineGetBlockSize

        protected int engineGetBlockSize()
        Specified by:
        engineGetBlockSize in class javax.crypto.CipherSpi
      • internalGetBlockSize

        protected int internalGetBlockSize()
      • engineGetOutputSize

        protected int engineGetOutputSize(int inputLen)
        Specified by:
        engineGetOutputSize in class javax.crypto.CipherSpi
      • internalGetOutputSize

        protected int internalGetOutputSize(int inputLen)
      • engineGetIV

        protected byte[] engineGetIV()
        Specified by:
        engineGetIV in class javax.crypto.CipherSpi
      • internalGetIV

        protected byte[] internalGetIV()
      • engineGetParameters

        protected java.security.AlgorithmParameters engineGetParameters()
        Specified by:
        engineGetParameters in class javax.crypto.CipherSpi
      • internalGetParameters

        protected java.security.AlgorithmParameters internalGetParameters()
      • engineInit

        protected void engineInit(int opmode,
                      java.security.Key key,
                      java.security.SecureRandom random)
                           throws java.security.InvalidKeyException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
      • internalInit

        protected void internalInit(int opmode,
                        java.security.Key key,
                        java.security.SecureRandom random)
                             throws java.security.InvalidKeyException
        Throws:
        java.security.InvalidKeyException
      • engineInit

        protected void engineInit(int opmode,
                      java.security.Key key,
                      java.security.spec.AlgorithmParameterSpec params,
                      java.security.SecureRandom random)
                           throws java.security.InvalidKeyException,
                                  java.security.InvalidAlgorithmParameterException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • engineInit

        protected void engineInit(int opmode,
                      java.security.Key key,
                      java.security.AlgorithmParameters params,
                      java.security.SecureRandom random)
                           throws java.security.InvalidKeyException,
                                  java.security.InvalidAlgorithmParameterException
        Specified by:
        engineInit in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • internalInit

        protected void internalInit(int opmode,
                        java.security.Key key,
                        java.security.AlgorithmParameters params,
                        java.security.SecureRandom random)
                             throws java.security.InvalidKeyException,
                                    java.security.InvalidAlgorithmParameterException
        Throws:
        java.security.InvalidKeyException
        java.security.InvalidAlgorithmParameterException
      • engineUpdate

        protected byte[] engineUpdate(byte[] in,
                          int inOfs,
                          int inLen)
        Specified by:
        engineUpdate in class javax.crypto.CipherSpi
      • internalUpdate

        protected byte[] internalUpdate(byte[] in,
                            int inOfs,
                            int inLen)
      • engineUpdate

        protected int engineUpdate(byte[] in,
                       int inOfs,
                       int inLen,
                       byte[] out,
                       int outOfs)
        Specified by:
        engineUpdate in class javax.crypto.CipherSpi
      • internalUpdate

        protected int internalUpdate(byte[] in,
                         int inOfs,
                         int inLen,
                         byte[] out,
                         int outOfs)
      • engineDoFinal

        protected byte[] engineDoFinal(byte[] in,
                           int inOfs,
                           int inLen)
                                throws javax.crypto.BadPaddingException,
                                       javax.crypto.IllegalBlockSizeException
        Specified by:
        engineDoFinal in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.BadPaddingException
        javax.crypto.IllegalBlockSizeException
      • internalDoFinal

        protected byte[] internalDoFinal(byte[] in,
                             int inOfs,
                             int inLen)
                                  throws javax.crypto.BadPaddingException,
                                         javax.crypto.IllegalBlockSizeException
        Throws:
        javax.crypto.BadPaddingException
        javax.crypto.IllegalBlockSizeException
      • engineDoFinal

        protected int engineDoFinal(byte[] in,
                        int inOfs,
                        int inLen,
                        byte[] out,
                        int outOfs)
                             throws javax.crypto.ShortBufferException,
                                    javax.crypto.BadPaddingException,
                                    javax.crypto.IllegalBlockSizeException
        Specified by:
        engineDoFinal in class javax.crypto.CipherSpi
        Throws:
        javax.crypto.ShortBufferException
        javax.crypto.BadPaddingException
        javax.crypto.IllegalBlockSizeException
      • internalDoFinal

        protected int internalDoFinal(byte[] in,
                          int inOfs,
                          int inLen,
                          byte[] out,
                          int outOfs)
                               throws javax.crypto.ShortBufferException,
                                      javax.crypto.BadPaddingException,
                                      javax.crypto.IllegalBlockSizeException
        Throws:
        javax.crypto.ShortBufferException
        javax.crypto.BadPaddingException
        javax.crypto.IllegalBlockSizeException
      • engineWrap

        protected byte[] engineWrap(java.security.Key key)
                             throws java.security.InvalidKeyException,
                                    javax.crypto.IllegalBlockSizeException
        Overrides:
        engineWrap in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        javax.crypto.IllegalBlockSizeException
      • internalWrap

        protected byte[] internalWrap(java.security.Key key)
                               throws java.security.InvalidKeyException,
                                      javax.crypto.IllegalBlockSizeException
        Throws:
        java.security.InvalidKeyException
        javax.crypto.IllegalBlockSizeException
      • engineUnwrap

        protected java.security.Key engineUnwrap(byte[] wrappedKey,
                                     java.lang.String algorithm,
                                     int type)
                                          throws java.security.InvalidKeyException,
                                                 java.security.NoSuchAlgorithmException
        Overrides:
        engineUnwrap in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
        java.security.NoSuchAlgorithmException
      • internalUnwrap

        protected java.security.Key internalUnwrap(byte[] wrappedKey,
                                       java.lang.String algorithm,
                                       int type)
                                            throws java.security.InvalidKeyException,
                                                   java.security.NoSuchAlgorithmException
        Throws:
        java.security.InvalidKeyException
        java.security.NoSuchAlgorithmException
      • engineGetKeySize

        protected int engineGetKeySize(java.security.Key key)
                                throws java.security.InvalidKeyException
        Overrides:
        engineGetKeySize in class javax.crypto.CipherSpi
        Throws:
        java.security.InvalidKeyException
      • internalGetKeySize

        protected int internalGetKeySize(java.security.Key key)
                                  throws java.security.InvalidKeyException
        Throws:
        java.security.InvalidKeyException
© Portions Copyright 2003, 2014, 2015, 2016 IBM Corporation. All rights reserved.
© Portions Copyright 2003, 2014 Oracle and/or its affiliates. All rights reserved.