(self, M, h=None, mgf=None, L=None)
return C
Internal method providing RSAES-OAEP-ENCRYPT as defined in Sect.
        7.1.1 of RFC 3447. Not intended to be used directly. Please, see
        encrypt() method for type "OAEP".


        Input:
           M  : message to be encrypted, an octet string of length mLen
                where mLen <= k - 2*hLen - 2 (k denotes the length in octets
                of the RSA modulus and hLen the length in octets of the hash
                function output)
           h  : hash function name (in 'md2', 'md4', 'md5', 'sha1', 'tls',
                'sha256', 'sha384'). hLen denotes the length in octets of
                the hash function output. 'sha1' is used by default if not
                provided.
           mgf: the mask generation function f : seed, maskLen -> mask
           L  : optional label to be associated with the message; the default
                value for L, if not provided is the empty string

        Output:
           ciphertext, an octet string of length k

        On error, None is returned.
Internal method providing RSAES-OAEP-ENCRYPT as defined in Sect.
        7.1.1 of RFC 3447. Not intended to be used directly. Please, see
        encrypt() method for type "OAEP".
Internal method providing RSAES - OAEP - ENCRYPT as defined in Sect . 7 . 1 . 1 of RFC 3447 . Not intended to be used directly . Please see encrypt () method for type OAEP .
def _rsaes_oaep_encrypt(self, M, h=None, mgf=None, L=None):
        """
        Internal method providing RSAES-OAEP-ENCRYPT as defined in Sect.
        7.1.1 of RFC 3447. Not intended to be used directly. Please, see
        encrypt() method for type "OAEP".


        Input:
           M  : message to be encrypted, an octet string of length mLen
                where mLen <= k - 2*hLen - 2 (k denotes the length in octets
                of the RSA modulus and hLen the length in octets of the hash
                function output)
           h  : hash function name (in 'md2', 'md4', 'md5', 'sha1', 'tls',
                'sha256', 'sha384'). hLen denotes the length in octets of
                the hash function output. 'sha1' is used by default if not
                provided.
           mgf: the mask generation function f : seed, maskLen -> mask
           L  : optional label to be associated with the message; the default
                value for L, if not provided is the empty string

        Output:
           ciphertext, an octet string of length k

        On error, None is returned.
        """
        # The steps below are the one described in Sect. 7.1.1 of RFC 3447.
        # 1) Length Checking
                                                    # 1.a) is not done
        mLen = len(M)
        if h is None:
            h = "sha1"
        if not _hashFuncParams.has_key(h):
            warning("Key._rsaes_oaep_encrypt(): unknown hash function %s.", h)
            return None
        hLen = _hashFuncParams[h][0]
        hFun = _hashFuncParams[h][1]
        k = self.modulusLen / 8
        if mLen > k - 2*hLen - 2:                   # 1.b)
            warning("Key._rsaes_oaep_encrypt(): message too long.")
            return None
        
        # 2) EME-OAEP encoding
        if L is None:                               # 2.a)
            L = ""
        lHash = hFun(L)
        PS = '\x00'*(k - mLen - 2*hLen - 2)         # 2.b)
        DB = lHash + PS + '\x01' + M                # 2.c)
        seed = randstring(hLen)                     # 2.d)
        if mgf is None:                             # 2.e)
            mgf = lambda x,y: pkcs_mgf1(x,y,h)
        dbMask = mgf(seed, k - hLen - 1)
        maskedDB = strxor(DB, dbMask)               # 2.f)
        seedMask = mgf(maskedDB, hLen)              # 2.g)
        maskedSeed = strxor(seed, seedMask)         # 2.h)
        EM = '\x00' + maskedSeed + maskedDB         # 2.i)

        # 3) RSA Encryption
        m = pkcs_os2ip(EM)                          # 3.a)
        c = self._rsaep(m)                          # 3.b)
        C = pkcs_i2osp(c, k)                        # 3.c)

        return C
def _rsaes_oaep_encrypt ( self , M , h = None , mgf = None , L = None ) : # The steps below are the one described in Sect. 7.1.1 of RFC 3447. # 1) Length Checking # 1.a) is not done mLen = len ( M ) if h is None : h = "sha1" if not _hashFuncParams . has_key ( h ) : warning ( "Key._rsaes_oaep_encrypt(): unknown hash function %s." , h ) return None hLen = _hashFuncParams [ h ] [ 0 ] hFun = _hashFuncParams [ h ] [ 1 ] k = self . modulusLen / 8 if mLen > k - 2 * hLen - 2 : # 1.b) warning ( "Key._rsaes_oaep_encrypt(): message too long." ) return None # 2) EME-OAEP encoding if L is None : # 2.a) L = "" lHash = hFun ( L ) PS = '\x00' * ( k - mLen - 2 * hLen - 2 ) # 2.b) DB = lHash + PS + '\x01' + M # 2.c) seed = randstring ( hLen ) # 2.d) if mgf is None : # 2.e) mgf = lambda x , y : pkcs_mgf1 ( x , y , h ) dbMask = mgf ( seed , k - hLen - 1 ) maskedDB = strxor ( DB , dbMask ) # 2.f) seedMask = mgf ( maskedDB , hLen ) # 2.g) maskedSeed = strxor ( seed , seedMask ) # 2.h) EM = '\x00' + maskedSeed + maskedDB # 2.i) # 3) RSA Encryption m = pkcs_os2ip ( EM ) # 3.a) c = self . _rsaep ( m ) # 3.b) C = pkcs_i2osp ( c , k ) # 3.c) return C