Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Add support for Zeros padding #43

Closed
AArnott opened this issue Oct 28, 2015 · 5 comments
Closed

Add support for Zeros padding #43

AArnott opened this issue Oct 28, 2015 · 5 comments

Comments

@AArnott
Copy link
Owner

AArnott commented Oct 28, 2015

This must be done for all platforms (iOS, Android, desktop, and WinRT)

The sponsor of this issue has provided this sample code snippet of what is done on Desktop that must be done in equivalence via PCLCrypto:

internal static string EncryptData(string data, string key)
{
    // Reference objects
    ICryptoTransform encryptor = null;
    MemoryStream msEncrypt = null;
    CryptoStream csEncrypt = null;

    try
    {
        // Encrypt the PUK Code
        var rijndael = new RijndaelManaged
        {
            Padding = PaddingMode.Zeros,
            Key = Encoding.ASCII.GetBytes(key),
            Mode = CipherMode.ECB
        };
        encryptor = rijndael.CreateEncryptor();

        //Encrypt the data.
        msEncrypt = new MemoryStream();
        csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);

        //Convert the data to a byte array.
        var toEncryptPuk = Encoding.ASCII.GetBytes(data);

        //Write all data to the crypt stream and flush it.
        csEncrypt.Write(toEncryptPuk, 0, toEncryptPuk.Length);
        csEncrypt.FlushFinalBlock();

        //Get encrypted array of bytes.
        var encryptedPuk = msEncrypt.ToArray();

        return ToHexString(encryptedPuk);
    }
    catch (Exception ex)
    {
        _logger.Error($"{"Static.EncryptData"}: {ex.Message}", ex);
        throw new InvalidOperationException(ex.Message, ex);
    }
    finally
    {
        csEncrypt?.Close();
        msEncrypt?.Close();
        encryptor?.Dispose();
    }
}
@jacodv
Copy link

jacodv commented Oct 28, 2015

Great news

AArnott added a commit that referenced this issue Oct 31, 2015
This required that we either add more enum values to the WinRT-based SymmetricAlgorithm enum in a multiplying fashion, or we change to using the individual component enums for algorithm name, mode, and padding. I went with the latter.

Currently, zeros padding is only known to work on desktop framework. It fails on WinRT till I rewrite its symmetric crypto in terms of BCrypt.

Work toward #43
@AArnott
Copy link
Owner Author

AArnott commented Oct 31, 2015

Work is ongoing in the issue43 branch.

@AArnott AArnott modified the milestone: 2.0 Nov 7, 2015
@AArnott
Copy link
Owner Author

AArnott commented Nov 20, 2015

Alright. This is now in master (#48) for Zeros padding support for desktop. It's not on other platforms yet, so I'm keeping this issue open.

@jacodv
Copy link

jacodv commented Nov 20, 2015

Great, and you were right. BouncyCastle does have it, the implementation is just a little diffferent

@AArnott
Copy link
Owner Author

AArnott commented Nov 24, 2015

Ongoing status of supporting platforms:

  • WinRT
  • UWP
  • Desktop
  • Windows Phone 8.1 (Appx)
  • iOS
  • Android

🔴 Windows Phone 8.x (Silverlight) -- not supported by platform

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants