Last active
October 20, 2016 02:21
-
-
Save smarenich/d15ae8efce7f5b2ff259c6896c8103be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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