Beispiel #1
0
def encryptRSAWithOAEP(message):
    global K0,K1,N,e,n
    valueMessage = long(message, 16)
    r = random.randrange(1 << (K0-1), (1 << K0) - 1)
    keccak = sha.sha3_384(hex(r))
    Gr = long(keccak.hexdigest(), 16) # 384 bits
    X = (valueMessage << K1) ^ Gr
    keccak = sha.sha3_256(hex(X))
    Hx = long(keccak.hexdigest(), 16) # 256 bits
    Y = r ^ Hx
    res = (X << K0) + Y
    # RSA encryption
    encrypt = pow(res, e, n)
    return encrypt
Beispiel #2
0
def decryptRSAWithOAEP(encrypt):
    global K0,K1,N,d,n
    # RSA decryption
    encryptValue = pow(encrypt, d, n)
    
    Y = encryptValue % (1 << K0)
    X = encryptValue >> K0
    keccak = sha.sha3_256(hex(X))
    Hx = long(keccak.hexdigest(), 16) # 256 bits
    r = Y ^ Hx
    keccak = sha.sha3_384(hex(r))
    Gr = long(keccak.hexdigest(), 16) # 384 bits
    message = X ^ Gr
    message >>= K1
    return hex(message)