Exemplo n.º 1
0
 def setTheKey(self, theKey):
     self._theKey = theKey
     self.p = _longToArray(keypair.p)
     self.q = _longToArray(keypair.q)
     self.pq = _longToArray(keypair.u)
     self.dp1 = _longToArray(keypair.d % (keypair.p - 1))
     self.dq1 = _longToArray(keypair.d % (keypair.q - 1))
     # someone should set size over there ...
     self._setInitialized()
Exemplo n.º 2
0
    def doFinal(self, inBuff, inOffset, inLength, outBuff, outOffset):
        Cipher.doFinal(self, inBuff, inOffset, inLength, outBuff, outOffset)

        data = [0 for i in xrange(inLength)]
        Util.arrayCopy(inBuff, inOffset, data, 0, inLength)
        if ((self.algorithm == self.ALG_RSA_PKCS1) and
            (self.mode == self.MODE_ENCRYPT)):
            data = self.EME_PKCS1_v1_5_enc(data)

        if len(data) != (self._theKey.getSize() // 8):
            raise CryptoException(CryptoException.ILLEGAL_VALUE)

        if self.mode == self.MODE_ENCRYPT:
            (res, ) = self._theKey._theKey.encrypt(_arrayTolong(data), None)
        else:
            res = self._theKey._theKey.decrypt(_arrayTolong(data))

        buf = _longToArray(res)

        # remove padding
        if ((self.algorithm == self.ALG_RSA_PKCS1) and
            (self.mode == self.MODE_DECRYPT)):
            buf = self.EME_PKCS1_v1_5_dec(buf)

        Util.arrayCopy(buf, 0, outBuff, outOffset, len(buf))

        return len(buf)
Exemplo n.º 3
0
 def setTheKey(self, theKey):
     self._theKey = theKey
     self.exponent = _longToArray(theKey.e)
     self.modulus = _longToArray(theKey.d)