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
}
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
}
I found
But I Don't understand what is going on...
The same code is working find If I call it from the terminal
But If I'm debug the code from Visual Studio Code the decrypt is allways returning me empty string.
Do you see what is going on ???