Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Help me convert this PHP code to C#

PHP Code

<?php 
       
        $key 
= openssl_random_pseudo_bytes(32);
 
       $iv = openssl_random_pseudo_bytes(12);
 
       $time = time();

 
       openssl_public_encrypt($key ,$encryptedAesKey, base64_decode($publicKey));
 
       $encrypted = openssl_encrypt($password, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $iv, $tag, strval($time)); 

This is what I currently have:

Code
           
           byte[] key = new byte[32];
           byte[] iv = new byte[12];
           RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
           rng.GetBytes(key);
           rng.GetBytes(iv);
           string rngString = Encoding.UTF8.GetString(key);

           string keyString = "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF4ZmFic2RVSDJLenRJaGs5MG42eQpUdk9teGZZRWU5MXA3OWRKYkxwa2g0eXJnNmtCQVppeUVoUHNlNlFpcHVxM2h0c0ppZnpGMzdlVUF0ODE2M3QxCnNLZXlBQzlxU0NKcndaUGZRb3ZyUHdIYjU1bVc2SGdZbUxsU0ovK2xKbzdsLzNzekRaYnd1dHVBYWxsZU9oZUcKQnlrYVgrRFhQbDRwbWVYLzZDUHRYS1Bkdi9xUGRYRytOZS9JaHJCNEtKdzl4NElMbGtnR3ZjaS8wblFKRjl1awpOYytVK3F2eE9TaWV4MjljT2pIUnNWOGpadnNxOGh5Q1EyK2hwNmdkSEdxUGoveW1zRG14RHd4MUF1ZUIrVlZiCnlzQ0RjYzdHdTNXdTRtK2dpZXN6NTRXTXlCQUFnVm9DSWRQMFU1Tis0S1duMWNhc1RoL3NZWVFFSFRaUis3UzcKcFFJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==";
           byte[] keyBytes = Convert.FromBase64String(keyString);
           string keyStringDecoded = Encoding.UTF8.GetString(keyBytes);

           string timeString = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
           byte[] timeBytes = Encoding.UTF8.GetBytes(timeString);

           OpenSSLProtect osp = new OpenSSLProtect();
           string encryptedAesKey = osp.OpenSSLEncrypt(rngString, keyStringDecoded);

           EncryptionService iq = new EncryptionService(32, 16, 12);
           string encrypted = iq.EncryptWithKey(password, rngString, timeBytes);

I'm getting this error: "System.FormatException: 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. '"

This is what I'm using for AES-256-GCM (EncryptionService / iq.EncryptWithKey): https://github.com/lukemerrett/Bouncy-Ca...Encryption

If anyone can help me, I would be so appreciative.

Cheers.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by FreddieXxMay 8, 2022 11:21 AM 2 144 May 8, 2022 11:21 AM
Last Post: FreddieXx
[C] by FhackMar 19, 2022 04:11 PM 27 972 Mar 19, 2022 04:11 PM
Last Post: focuswow35
[Python] by SIM-4791248Jun 19, 2021 03:13 AM 16 453 Jun 19, 2021 03:13 AM
Last Post: Goodies