Thanks, I am aware of the various pitfalls of the methods and algorithms used.  
Unfortunately we sit with 10+ years of legacy code and the content it created 
of the 10 years.

I have the code working now with PCLCrypto this is the implementation on 
PCLCrypto below.  The BouncyCastle actually created the extra block in 
encryption, and expects it again in decryption, because if I strip the extra 
block then it doesn't decrypt.  I thought it was some initializing value that I 
didn't set correctly

Thanks for insights so far

public class PclCryptEngine : CryptoBase, ICrypto
{
        public string Encrypt(string plain, string key)
        {
                var keyData = Convert.FromBase64String(key);
                var aesKeyZerosPadding = 
WinRTCrypto.SymmetricKeyAlgorithmProvider
                 .OpenAlgorithm(SymmetricAlgorithmName.Aes, 
SymmetricAlgorithmMode.Ecb, SymmetricAlgorithmPadding.Zeros)
                 .CreateSymmetricKey(keyData);

                var data = Encoding.UTF8.GetBytes(plain);

                byte[] cipherText = 
WinRTCrypto.CryptographicEngine.Encrypt(aesKeyZerosPadding, data, null);

                _dataPCLBytes = data;
                _keyPCLBytes = keyData;
                _encryptedPCLBytes = cipherText;

                return ToHexString(cipherText);
        }

        public string Decrypt(string encryptedString, string key)
        {
                int discarded;
                var aesKeyZerosPadding = 
WinRTCrypto.SymmetricKeyAlgorithmProvider
                 .OpenAlgorithm(SymmetricAlgorithmName.Aes, 
SymmetricAlgorithmMode.Ecb, SymmetricAlgorithmPadding.Zeros)
                 .CreateSymmetricKey(Convert.FromBase64String(key));

                byte[] hexBytes = GetBytes(encryptedString, out discarded);
                byte[] plainBytes = 
WinRTCrypto.CryptographicEngine.Decrypt(aesKeyZerosPadding, hexBytes, null);

                return GetStringValue(plainBytes);
        }
}


Reply via email to