
while len ( padding ) > block = _pad_for_signing(b ' hello ', 16) > len(block) 16 > block b ' \ x00 \ x01 ' > block b ' \ x00hello ' > block b ' \ xff \ xff \ xff \ xff \ xff \ xff \ xff \ xff ' """ max_msglength = target_length - 11 msglength = len ( message ) if msglength > max_msglength : raise OverflowError ( ' %i bytes needed for message, but there is only ' ' space for %i ' % ( msglength, max_msglength ) ) padding_length = target_length - msglength - 3 return b ' '. :return: 00 02 RANDOM_DATA 00 MESSAGE > block = _pad_for_encryption(b ' hello ', 16) > len(block) 16 > block b ' \ x00 \ x02 ' > block b ' \ x00hello ' """ max_msglength = target_length - 11 msglength = len ( message ) if msglength > max_msglength : raise OverflowError ( ' %i bytes needed for message, but there is only ' ' space for %i ' % ( msglength, max_msglength ) ) # Get random padding padding = b ' ' padding_length = target_length - msglength - 3 # We remove 0-bytes, so we'll end up with less padding than we've asked for, # so keep adding data until we're at the correct length. """ def _pad_for_encryption ( message, target_length ) : r """ Pads the message for encryption, returning the padded message. """ class VerificationError ( CryptoError ) : """ Raised when verification fails. """ class DecryptionError ( CryptoError ) : """ Raised when decryption fails. HASH_ASN1 = class CryptoError ( Exception ) : """ Base class for all exceptions in this module. _compat import range from rsa import common, transform, core # ASN.1 codes that describe the hash algorithm used. DO NOT PASS SUCH INFORMATION to your users.

The exceptions that are raised contain the Python traceback information, which can be used to deduce where in the process the failure occurred. WARNING: this module leaks information when decryption fails. This makes these methods much more secure than the ones in the ``rsa`` module.

For a very clear example, read At least 8 bytes of random padding is used when encrypting a message. """ Functions for PKCS#1 version 1.5 encryption and signing This module implements certain functionality from PKCS#1 version 1.5. # See the License for the specific language governing permissions and # limitations under the License. # You may obtain a copy of the License at # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Stüvel # Licensed under the Apache License, Version 2.0 (the "License") # you may not use this file except in compliance with the License. # -*- coding: utf-8 -*- # Copyright 2011 Sybren A.
