cryptography in c# ( Python Reference Available )

Job ID: 32617611

Budget: ₹600 – ₹1,500 INR

Hi,
We have a code in Python for cryptography, we need the same results from c#.

There are 3 steps
1. Apply function on plain text
2. Swap position with | symbol
3. Again Apply function

--------------- Sample Code Starts Here ------------------

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
import base64

secret_key = "ZENmKvMZ6VdkaHIxa3mOKckA3xsj6yuI".encode('utf-8')
iv = base64.b64decode("AAAAAAAAAAAAAAAAAAAAAA==")
text = "Ifz7i3Tphhd+5lBSAIrPWjCr+xjLcLxWSmOfy8d+vdAbPDBpRU3vIqTbB4vnL2zBJFgMLyRZ0Ls="


def encryptAPIString(plaintext):
raw = plaintext.encode('utf-8')
encryptor = Cipher(algorithms.AES(secret_key),modes.GCM(iv, None, 16), default_backend()
).encryptor()
ciphertext = encryptor.update(raw) + encryptor.finalize()
return base64.b64encode(ciphertext+encryptor.tag)


def decryptAPIString(ciphertext):
enc = base64.b64decode(ciphertext)[:-16]
decryptor = Cipher(algorithms.AES(secret_key),modes.GCM(iv), default_backend()).decryptor()
return decryptor.update(enc)

if __name__ == '__main__':
# step 1 : Decryption
decryptedString = (decryptAPIString(text)).decode("utf-8") #using decryptAPIString()
print("decryptedString :"+decryptedString) # Results of Decryption using decryptAPIString()
ResultOfDecrypt = decryptedString.split("|") # Spliting of string from -| Responce -->>> VhkOiA4FQhql1VOOEvBKkLFxdqVZDqyW|2400597
Swap_ResultOfDecrypt = str(ResultOfDecrypt[1]) + str('|') + str(ResultOfDecrypt[0]) # Interchaning postion Responce -->>> 2400597|VhkOiA4FQhql1VOOEvBKkLFxdqVZDqyW
print("Swap_ResultOfDecrypt :", Swap_ResultOfDecrypt)
encryptedStr = (encryptAPIString(Swap_ResultOfDecrypt)).decode("utf-8") #using encryptAPIString()
print("encryptedStr :", encryptedStr) #Responce ---->> RaCg9CiRhS155kpxWJ20UyS1yD+RarVha2SL2uhDgv8Df1IDMQmvQrbDrqqs1sAjVyvmXtPSLTQ=
Related categories: Python .NET C# Programming VB.NET