Question
· May 16

RSA Encryption Decryption

Hi guys,

 

I try to make a test of encryption, decryption of a simple text.

I can crypt my text, but I can't decrypt it, do you see somewhere a dummy error of my part ?

Thanks for help

ClassMethod UnitTest()

{

  set inputPlainText = "David"

 

  // get private key

  set privKeyFileName = "C:\temp\toto.pem"

  set privobjCharFile = ##class(%Stream.FileCharacter).%New()

  set privobjCharFile.Filename = privKeyFileName

  set privKey = privobjCharFile.Read()

 

  set Inputbase64 = $SYSTEM.Encryption.Base64Encode(inputPlainText)

 

  // encrypte text using RSA

  set encryptText = $System.Encryption.RSAEncrypt(Inputbase64, privKey)

 

  // decrypt text using RSA

  set outputbase64 = $System.Encryption.RSADecrypt(encryptText, privKey)

 

  set plaintext = $SYSTEM.Encryption.Base64Decode(outputbase64)

 

  return plaintext

}

Product version: IRIS 2023.1
$ZV: IRIS for Windows (x86-64) 2023.1.1 (Build 380) Fri Jul 7 2023 23:59:41 EDT
Discussion (2)1
Log in or sign up to continue

I use the same key for both operation, my bad, but even using the private and the public key don't get me to the goal

ClassMethod UnitTest()

{

  set inputPlainText = "David"

  set privKeyFileName = "C:\temp\toto.pem"

  set pubKeyFileName = "C:\temp\toto_pub.pem"

  // Lire la clé privée depuis le fichier

  set privobjCharFile = ##class(%Stream.FileCharacter).%New()

  set privobjCharFile.Filename = privKeyFileName

  set privKey = privobjCharFile.Read()

  // Lire la clé publique depuis le fichier

  set pubobjCharFile = ##class(%Stream.FileCharacter).%New()

  set pubobjCharFile.Filename = pubKeyFileName

  set pubKey = pubobjCharFile.Read()

  // Chiffrer le texte en utilisant RSA

  set encryptedText = $System.Encryption.RSAEncrypt(inputPlainText, privKey)

  // Déchiffrer le texte en utilisant RSA avec la clé publique

  set decryptedText = $System.Encryption.RSADecrypt(encryptedText, pubKey)

  // retour

  quit decryptedText

}