Benigno Bello
Benigno Bello

Reputation: 1

Why am I NOT getting value when I execute the decrypt method on my python code?

After to generate a pear of assimetric RSA keys, I have a python code method to encrypt and decrypt string text, but decrypt value don't bring me the value what I pretend.

When I execute for value == 1, it works well, but when I try to execute with value == 0, it doesn't give any result.

def enc_pubK(value, txt, path_chv_pub = None, path_chv_priv = None):
        
        
        if value == 1:
            
            if path_chv_pub:
            
                with open(str(path_chv_pub), 'rb') as arq_pub:
                    
                    chave_publica = RSA.import_key(arq_pub.read())
                    cipher = PKCS1_OAEP.new(chave_publica)
                    negocio = cipher.encrypt(txt.encode())
                    print(negocio)
                    
        if value == 0:
            
            if path_chv_priv:
                
                with open(str(path_chv_priv), "rb") as arq_pri:
                    cha_pri = RSA.import_key(arq_pri.read())
                    decipher = PKCS1_OAEP.new(cha_pri)
                    vigor = decipher.decrypt(txt.decode())
                    print(vigor)

Upvotes: 0

Views: 39

Answers (0)

Related Questions