Skip to content

Instantly share code, notes, and snippets.

@smarenich
Last active October 20, 2016 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smarenich/d15ae8efce7f5b2ff259c6896c8103be to your computer and use it in GitHub Desktop.
Save smarenich/d15ae8efce7f5b2ff259c6896c8103be to your computer and use it in GitHub Desktop.
using System;
using PX.Data;
using PX.Objects.IN;
using PX.DataSync;
using PX.Common.Cryptography;
using System.Security.Cryptography;
using System.Web.Configuration;
using System.Text;
namespace MyProject
{
public class EncryptedACHProvider : ACHProvider
{
public override string ProviderName
{
get
{
return "Encrypted ACH";
}
}
protected override PX.SM.FileInfo SetFile(byte[] bytes)
{
SymmetricCryptoProvider provider = CreateSymetricProvider();
bytes = provider.Encrypt(bytes);
return base.SetFile(bytes);
}
private static SymmetricCryptoProvider CreateSymetricProvider()
{
MachineKeySection keySection = (MachineKeySection)WebConfigurationManager.GetSection("system.web/machineKey");
TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
byte[] IV = new byte[provider.IV.Length];
Array.Copy(CryptoProvider.HexStringToByteArray(keySection.DecryptionKey), IV, IV.Length);
byte[] key = new byte[provider.Key.Length];
Array.Copy(CryptoProvider.HexStringToByteArray(keySection.ValidationKey), key, key.Length);
return new SymmetricCryptoProvider(
provider.CreateEncryptor(key, IV),
provider.CreateDecryptor(key, IV));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment