Browse Source

svn move to git

master
robin 8 years ago
commit
83c26f407e
357 changed files with 40879 additions and 0 deletions
  1. +38
    -0
      ABCClient2.sln
  2. BIN
      ABCClient2.suo
  3. +134
    -0
      B2B/B2B.csproj
  4. +35
    -0
      B2B/Properties/AssemblyInfo.cs
  5. +461
    -0
      B2B/TrustPay/SupportClass.cs
  6. +15
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CERT_EXTENSION.cs
  7. +26
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CERT_PUBLIC_KEY_INFO.cs
  8. +20
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CRYPT_KEY_PROV_INFO.cs
  9. +16
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CertificateContext.cs
  10. +15
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CertificateExtension.cs
  11. +37
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CertificateInfo.cs
  12. +13
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CertificateNameInfo.cs
  13. +14
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/CertificateNameValue.cs
  14. +11
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/AuthType.cs
  15. +1221
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/Certificate.cs
  16. +239
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateChain.cs
  17. +19
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateChainOptions.cs
  18. +26
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateException.cs
  19. +26
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStatus.cs
  20. +512
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStore.cs
  21. +79
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStoreCollection.cs
  22. +11
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStoreType.cs
  23. +144
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateVerificationResult.cs
  24. +131
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/DistinguishedName.cs
  25. +148
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/DistinguishedNameList.cs
  26. +19
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/Extension.cs
  27. +12
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/HashType.cs
  28. +17
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/KeyUsage.cs
  29. +12
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/KeysetLocation.cs
  30. +65
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/NameAttribute.cs
  31. +18
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/StoreLocation.cs
  32. +27
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Certificates/VerificationFlags.cs
  33. +15
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/ChainParameters.cs
  34. +14
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/ChainPolicyParameters.cs
  35. +16
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/ChainPolicyStatus.cs
  36. +43
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/ARCFourManaged.cs
  37. +138
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/ARCFourManagedTransform.cs
  38. +13
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/CryptoAlgorithm.cs
  39. +11
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/CryptoMethod.cs
  40. +11
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/CryptoProvider.cs
  41. +15
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/PUBLICKEYSTRUC.cs
  42. +11
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/ProtectionType.cs
  43. +112
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/RC4.cs
  44. +236
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/RC4CryptoServiceProvider.cs
  45. +120
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/RC4UnmanagedTransform.cs
  46. +572
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/SymmetricKey.cs
  47. +13
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/DataBlob.cs
  48. +22
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/PROV_ENUMALGS_EX.cs
  49. +18
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/PUBLIC_KEY_BLOB.cs
  50. +15
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/RdnAttribute.cs
  51. +13
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/RelativeDistinguishedName.cs
  52. +269
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/SecurityConstants.cs
  53. +26
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/SecurityException.cs
  54. +33
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/Signature.cs
  55. +15
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/SslPolicyParameters.cs
  56. +172
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/SspiProvider.cs
  57. +13
    -0
      B2B/TrustPay/com/hitrust/b2b/Security/TrustListUsage.cs
  58. +205
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/Base64.cs
  59. +143
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/DataVerifier.cs
  60. +176
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/HiCalendar.cs
  61. +114
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/IniFileParser.cs
  62. +100
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/LogWriter.cs
  63. +416
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/MerchantConfig.cs
  64. +15
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/MyPolicy.cs
  65. +96
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/TrxException.cs
  66. +157
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/TrxRequest.cs
  67. +136
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/TrxResponse.cs
  68. +130
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/XMLDocument.cs
  69. +87
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/DownloadTrnxRequest.cs
  70. +339
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/FreezeRequest.cs
  71. +484
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/FreezeTransferRequest.cs
  72. +310
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/FundTransferRequest.cs
  73. +484
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/PartFreezeTransferRequest.cs
  74. +397
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/PartUnFreezeRequest.cs
  75. +484
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/PayFeeRequest.cs
  76. +88
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/QueryTrnxRequest.cs
  77. +106
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxInfo.cs
  78. +181
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxItem.cs
  79. +68
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxItems.cs
  80. +103
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxRemark.cs
  81. +68
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxRemarks.cs
  82. +37
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxResult.cs
  83. +20
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrxType.cs
  84. +397
    -0
      B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/UnFreezeRequest.cs
  85. BIN
      B2B/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  86. +167
    -0
      B2C/B2C.csproj
  87. +35
    -0
      B2C/Properties/AssemblyInfo.cs
  88. +216
    -0
      B2C/TrustPay/SupportClass.cs
  89. +15
    -0
      B2C/TrustPay/com/hitrust/Security/CERT_EXTENSION.cs
  90. +26
    -0
      B2C/TrustPay/com/hitrust/Security/CERT_PUBLIC_KEY_INFO.cs
  91. +20
    -0
      B2C/TrustPay/com/hitrust/Security/CRYPT_KEY_PROV_INFO.cs
  92. +16
    -0
      B2C/TrustPay/com/hitrust/Security/CertificateContext.cs
  93. +15
    -0
      B2C/TrustPay/com/hitrust/Security/CertificateExtension.cs
  94. +37
    -0
      B2C/TrustPay/com/hitrust/Security/CertificateInfo.cs
  95. +13
    -0
      B2C/TrustPay/com/hitrust/Security/CertificateNameInfo.cs
  96. +14
    -0
      B2C/TrustPay/com/hitrust/Security/CertificateNameValue.cs
  97. +11
    -0
      B2C/TrustPay/com/hitrust/Security/Certificates/AuthType.cs
  98. +1032
    -0
      B2C/TrustPay/com/hitrust/Security/Certificates/Certificate.cs
  99. +239
    -0
      B2C/TrustPay/com/hitrust/Security/Certificates/CertificateChain.cs
  100. +19
    -0
      B2C/TrustPay/com/hitrust/Security/Certificates/CertificateChainOptions.cs

+ 38
- 0
ABCClient2.sln View File

@ -0,0 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Market", "Market\Market.csproj", "{0B893BDB-B98C-49C6-9B96-119BEC2F8FDC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "B2B", "B2B\B2B.csproj", "{68082B37-B3DF-4D87-B366-34F658F3489B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "B2C", "B2C\B2C.csproj", "{605CA8A0-2034-4675-8D2C-64619C7F2AAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{841B615A-7F71-4E69-B5AA-BCDE2C47B680}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0B893BDB-B98C-49C6-9B96-119BEC2F8FDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B893BDB-B98C-49C6-9B96-119BEC2F8FDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B893BDB-B98C-49C6-9B96-119BEC2F8FDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B893BDB-B98C-49C6-9B96-119BEC2F8FDC}.Release|Any CPU.Build.0 = Release|Any CPU
{68082B37-B3DF-4D87-B366-34F658F3489B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68082B37-B3DF-4D87-B366-34F658F3489B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68082B37-B3DF-4D87-B366-34F658F3489B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68082B37-B3DF-4D87-B366-34F658F3489B}.Release|Any CPU.Build.0 = Release|Any CPU
{605CA8A0-2034-4675-8D2C-64619C7F2AAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{605CA8A0-2034-4675-8D2C-64619C7F2AAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{605CA8A0-2034-4675-8D2C-64619C7F2AAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{605CA8A0-2034-4675-8D2C-64619C7F2AAB}.Release|Any CPU.Build.0 = Release|Any CPU
{841B615A-7F71-4E69-B5AA-BCDE2C47B680}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{841B615A-7F71-4E69-B5AA-BCDE2C47B680}.Debug|Any CPU.Build.0 = Debug|Any CPU
{841B615A-7F71-4E69-B5AA-BCDE2C47B680}.Release|Any CPU.ActiveCfg = Release|Any CPU
{841B615A-7F71-4E69-B5AA-BCDE2C47B680}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

BIN
ABCClient2.suo View File


+ 134
- 0
B2B/B2B.csproj View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{68082B37-B3DF-4D87-B366-34F658F3489B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bwp.ABCClient2.B2B</RootNamespace>
<AssemblyName>ABCClient2.B2B</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<KeyContainerName>BwpApp</KeyContainerName></PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"><SpecificVersion>False</SpecificVersion></Reference>
<Reference Include="System.Core"><SpecificVersion>False</SpecificVersion></Reference>
<Reference Include="System.Xml.Linq"><SpecificVersion>False</SpecificVersion></Reference>
<Reference Include="System.Data.DataSetExtensions"><SpecificVersion>False</SpecificVersion></Reference>
<Reference Include="Microsoft.CSharp"><SpecificVersion>False</SpecificVersion></Reference>
<Reference Include="System.Data"><SpecificVersion>False</SpecificVersion></Reference>
<Reference Include="System.Xml"><SpecificVersion>False</SpecificVersion></Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\version\tslib_version.cs"><Link>tslib_version.cs</Link></Compile><Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CertificateContext.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CertificateExtension.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CertificateInfo.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CertificateNameInfo.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CertificateNameValue.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\AuthType.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\Certificate.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateChain.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateChainOptions.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateException.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateStatus.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateStore.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateStoreCollection.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateStoreType.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\CertificateVerificationResult.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\DistinguishedName.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\DistinguishedNameList.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\Extension.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\HashType.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\KeysetLocation.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\KeyUsage.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\NameAttribute.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\StoreLocation.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Certificates\VerificationFlags.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CERT_EXTENSION.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CERT_PUBLIC_KEY_INFO.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\ChainParameters.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\ChainPolicyParameters.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\ChainPolicyStatus.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\ARCFourManaged.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\ARCFourManagedTransform.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\CryptoAlgorithm.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\CryptoMethod.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\CryptoProvider.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\ProtectionType.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\PUBLICKEYSTRUC.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\RC4.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\RC4CryptoServiceProvider.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\RC4UnmanagedTransform.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Cryptography\SymmetricKey.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\CRYPT_KEY_PROV_INFO.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\DataBlob.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\PROV_ENUMALGS_EX.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\PUBLIC_KEY_BLOB.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\RdnAttribute.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\RelativeDistinguishedName.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\SecurityConstants.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\SecurityException.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\Signature.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\SslPolicyParameters.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\SspiProvider.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\Security\TrustListUsage.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\DownloadTrnxRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\FreezeRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\FreezeTransferRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\FundTransferRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\PartFreezeTransferRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\PartUnFreezeRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\PayFeeRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\QueryTrnxRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\TrnxInfo.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\TrnxItem.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\TrnxItems.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\TrnxRemark.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\TrnxRemarks.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\TrnxResult.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\TrxType.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\b2b\UnFreezeRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\Base64.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\DataVerifier.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\HiCalendar.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\IniFileParser.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\LogWriter.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\MerchantConfig.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\MyPolicy.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\TrxException.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\TrxRequest.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\TrxResponse.cs" />
<Compile Include="TrustPay\com\hitrust\b2b\trustpay\client\XMLDocument.cs" />
<Compile Include="TrustPay\SupportClass.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

+ 35
- 0
B2B/Properties/AssemblyInfo.cs View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("B2B")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("B2B")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("2ddabb69-2e58-4197-b209-e77214af7be3")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]

+ 461
- 0
B2B/TrustPay/SupportClass.cs View File

@ -0,0 +1,461 @@
using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Security.Cryptography;
public class SupportClass
{
public static int ReadInput(Stream sourceStream, ref sbyte[] target, int start, int count)
{
byte[] buffer = new byte[target.Length];
int num = sourceStream.Read(buffer, start, count);
for (int i = start; i < (start + num); i++) {
target[i] = (sbyte)buffer[i];
}
return num;
}
public static int ReadInput(TextReader sourceTextReader, ref sbyte[] target, int start, int count)
{
char[] buffer = new char[target.Length];
int num = sourceTextReader.Read(buffer, start, count);
for (int i = start; i < (start + num); i++) {
target[i] = (sbyte)buffer[i];
}
return num;
}
public static byte[] ToByteArray(string sourceString)
{
byte[] buffer = new byte[sourceString.Length];
for (int i = 0; i < sourceString.Length; i++) {
buffer[i] = (byte)sourceString[i];
}
return buffer;
}
public static byte[] ToByteArray(byte[] sbyteArray)
{
byte[] buffer = new byte[sbyteArray.Length];
for (int i = 0; i < sbyteArray.Length; i++) {
buffer[i] = sbyteArray[i];
}
return buffer;
}
public static char[] ToCharArray(byte[] byteArray)
{
char[] array = new char[byteArray.Length];
byteArray.CopyTo(array, 0);
return array;
}
public static char[] ToCharArray(sbyte[] sByteArray)
{
char[] array = new char[sByteArray.Length];
sByteArray.CopyTo(array, 0);
return array;
}
public static sbyte[] ToSByteArray(byte[] byteArray)
{
sbyte[] numArray = new sbyte[byteArray.Length];
for (int i = 0; i < byteArray.Length; i++) {
numArray[i] = (sbyte)byteArray[i];
}
return numArray;
}
public static void WriteStackTrace(Exception throwable, TextWriter stream)
{
stream.Write(throwable.StackTrace);
stream.Flush();
}
public class CalendarManager
{
public const int DATE = 2;
public const int DAY_OF_MONTH = 7;
public const int HOUR = 3;
public const int HOUR_OF_DAY = 8;
public static CalendarHashTable manager = new CalendarHashTable();
public const int MILLISECOND = 6;
public const int MINUTE = 4;
public const int MONTH = 1;
public const int SECOND = 5;
public const int YEAR = 0;
public class CalendarHashTable : Hashtable
{
public void Clear(Calendar calendar)
{
if (this[calendar] != null) {
this.Remove(calendar);
}
}
public void Clear(Calendar calendar, int field)
{
if (this[calendar] != null) {
this.Remove(calendar);
} else {
this.Set(calendar, field, 0);
}
}
public int Get(Calendar calendar, int field)
{
if (this[calendar] != null) {
switch (field) {
case 0:
return ((CalendarProperties)this[calendar]).dateTime.Year;
case 1:
return (((CalendarProperties)this[calendar]).dateTime.Month - 1);
case 2:
return ((CalendarProperties)this[calendar]).dateTime.Day;
case 3: {
int hour = ((CalendarProperties)this[calendar]).dateTime.Hour;
if (hour > 12) {
return (hour - 12);
}
return hour;
}
case 4:
return ((CalendarProperties)this[calendar]).dateTime.Minute;
case 5:
return ((CalendarProperties)this[calendar]).dateTime.Second;
case 6:
return ((CalendarProperties)this[calendar]).dateTime.Millisecond;
case 7:
return ((CalendarProperties)this[calendar]).dateTime.Day;
case 8:
return ((CalendarProperties)this[calendar]).dateTime.Hour;
}
return 0;
}
CalendarProperties properties = new CalendarProperties {
dateTime = DateTime.Now
};
this.Add(calendar, properties);
return this.Get(calendar, field);
}
public DateTime GetDateTime(Calendar calendar)
{
if (this[calendar] != null) {
return ((CalendarProperties)this[calendar]).dateTime;
}
CalendarProperties properties = new CalendarProperties {
dateTime = DateTime.Now
};
this.Add(calendar, properties);
return this.GetDateTime(calendar);
}
public DayOfWeek GetFirstDayOfWeek(Calendar calendar)
{
if ((this[calendar] != null) && (((CalendarProperties)this[calendar]).dateTimeFormat != null)) {
return ((CalendarProperties)this[calendar]).dateTimeFormat.FirstDayOfWeek;
}
CalendarProperties properties = new CalendarProperties {
dateTimeFormat = new DateTimeFormatInfo()
};
properties.dateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
this.Add(calendar, properties);
return this.GetFirstDayOfWeek(calendar);
}
public void Set(Calendar calendar, int field, int fieldValue)
{
if (this[calendar] == null) {
CalendarProperties properties = new CalendarProperties {
dateTime = DateTime.Now
};
this.Add(calendar, properties);
this.Set(calendar, field, fieldValue);
} else {
DateTime dateTime = ((CalendarProperties)this[calendar]).dateTime;
switch (field) {
case 0:
dateTime = dateTime.AddYears(fieldValue - dateTime.Year);
break;
case 1:
dateTime = dateTime.AddMonths(fieldValue - (dateTime.Month + 1));
break;
case 2:
dateTime = dateTime.AddDays((double)(fieldValue - dateTime.Day));
break;
case 3:
dateTime = dateTime.AddHours((double)(fieldValue - dateTime.Hour));
break;
case 4:
dateTime = dateTime.AddMinutes((double)(fieldValue - dateTime.Minute));
break;
case 5:
dateTime = dateTime.AddSeconds((double)(fieldValue - dateTime.Second));
break;
case 6:
dateTime = dateTime.AddMilliseconds((double)(fieldValue - dateTime.Millisecond));
break;
case 7:
dateTime = dateTime.AddDays((double)(fieldValue - dateTime.Day));
break;
case 8:
dateTime = dateTime.AddHours((double)(fieldValue - dateTime.Hour));
break;
}
((CalendarProperties)this[calendar]).dateTime = dateTime;
}
}
public void Set(Calendar calendar, int year, int month, int day)
{
if (this[calendar] != null) {
this.Set(calendar, 0, year);
this.Set(calendar, 1, month);
this.Set(calendar, 2, day);
} else {
CalendarProperties properties = new CalendarProperties {
dateTime = new DateTime(year, month + 1, day)
};
this.Add(calendar, properties);
}
}
public void Set(Calendar calendar, int year, int month, int day, int hour, int minute)
{
if (this[calendar] != null) {
this.Set(calendar, 0, year);
this.Set(calendar, 1, month);
this.Set(calendar, 2, day);
this.Set(calendar, 3, hour);
this.Set(calendar, 4, minute);
} else {
CalendarProperties properties = new CalendarProperties {
dateTime = new DateTime(year, month + 1, day, hour, minute, 0)
};
this.Add(calendar, properties);
}
}
public void Set(Calendar calendar, int year, int month, int day, int hour, int minute, int second)
{
if (this[calendar] != null) {
this.Set(calendar, 0, year);
this.Set(calendar, 1, month);
this.Set(calendar, 2, day);
this.Set(calendar, 3, hour);
this.Set(calendar, 4, minute);
this.Set(calendar, 5, second);
} else {
CalendarProperties properties = new CalendarProperties {
dateTime = new DateTime(year, month + 1, day, hour, minute, second)
};
this.Add(calendar, properties);
}
}
public void SetDateTime(Calendar calendar, DateTime date)
{
if (this[calendar] != null) {
((CalendarProperties)this[calendar]).dateTime = date;
} else {
CalendarProperties properties = new CalendarProperties {
dateTime = date
};
this.Add(calendar, properties);
}
}
public void SetFirstDayOfWeek(Calendar calendar, DayOfWeek firstDayOfWeek)
{
if ((this[calendar] != null) && (((CalendarProperties)this[calendar]).dateTimeFormat != null)) {
((CalendarProperties)this[calendar]).dateTimeFormat.FirstDayOfWeek = firstDayOfWeek;
} else {
CalendarProperties properties = new CalendarProperties {
dateTimeFormat = new DateTimeFormatInfo()
};
this.Add(calendar, properties);
this.SetFirstDayOfWeek(calendar, firstDayOfWeek);
}
}
public void SetTimeInMilliseconds(Calendar calendar, long milliseconds)
{
if (this[calendar] != null) {
((CalendarProperties)this[calendar]).dateTime = new DateTime(milliseconds);
} else {
CalendarProperties properties = new CalendarProperties {
dateTime = new DateTime(0x2710L * milliseconds)
};
this.Add(calendar, properties);
}
}
private class CalendarProperties
{
public DateTime dateTime;
public DateTimeFormatInfo dateTimeFormat;
}
}
}
public class DigitalSignature
{
private string algorithmName;
private byte[] data;
private AsymmetricSignatureDeformatter deformatter;
private AsymmetricSignatureFormatter formatter;
private HashAlgorithm hashAlgorithm;
private int objective;
private int position;
protected DigitalSignature() {}
public static DigitalSignature GetInstance(string algorithmName)
{
if (!algorithmName.ToLower().Equals("sha1withdsa") && !algorithmName.ToLower().Equals("shawithdsa")) {
throw new Exception("Algorithm not supported");
}
return new DigitalSignature {
formatter = new DSASignatureFormatter(),
deformatter = new DSASignatureDeformatter(),
hashAlgorithm = new SHA1Managed(),
algorithmName = "SHAwithDSA",
objective = 0
};
}
private void Reset()
{
this.data = null;
this.position = 0;
}
public byte[] Sign()
{
byte[] buffer = null;
if (this.objective != 1) {
throw new Exception("Object was not created for signing");
}
buffer = this.formatter.CreateSignature(this.Data);
this.Reset();
return buffer;
}
public void Signing()
{
this.objective = 1;
}
public override string ToString()
{
string str = "Instance of DigitalSignature for ";
if (this.objective == 1) {
str = str + "signing ";
} else {
str = str + "verification ";
}
return (str + "using " + this.AlgorithmName + " algorithm");
}
public void Update(byte[] newData)
{
if (this.position == 0) {
this.Data = newData;
this.hashAlgorithm.TransformBlock(newData, 0, newData.Length, this.Data, 0);
this.position = this.Data.Length - 1;
} else {
byte[] data = this.Data;
this.Data = new byte[(newData.Length + this.position) + 1];
data.CopyTo(this.Data, 0);
byte[] outputBuffer = newData;
this.hashAlgorithm.TransformBlock(newData, 0, outputBuffer.Length, outputBuffer, 0);
outputBuffer.CopyTo(this.Data, data.Length);
this.position = this.Data.Length - 1;
}
}
public void Update(byte newData)
{
byte[] buffer = new byte[] {newData};
this.Update(buffer);
}
public void Update(byte[] newData, int offset, int count)
{
byte[] destinationArray = new byte[count];
Array.Copy(newData, offset, destinationArray, 0, count);
this.Update(destinationArray);
}
public void Verification()
{
this.objective = 2;
}
public bool Verify(byte[] signature)
{
bool flag = false;
if (this.objective != 2) {
throw new Exception("Object was not created for verification");
}
flag = this.deformatter.VerifySignature(this.Data, signature);
this.Reset();
return flag;
}
public string AlgorithmName
{
get { return this.algorithmName; }
}
public byte[] Data
{
get { return this.data; }
set { this.data = value; }
}
}
public class KeySupport
{
private readonly KeyedHashAlgorithm algorithm;
public KeySupport() {}
public KeySupport(KeyedHashAlgorithm algorithm)
{
this.algorithm = algorithm;
}
public string GetAlgorithm()
{
return this.algorithm.ToString();
}
public byte[] Key
{
get { return this.algorithm.Key; }
}
}
public class PrivateKeySupport : KeySupport {}
public class PublicKeySupport : KeySupport {}
}

+ 15
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CERT_EXTENSION.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CERT_EXTENSION
{
public IntPtr pszObjId;
public int fCritical;
public int ValuecbData;
public IntPtr ValuepbData;
}
}

+ 26
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CERT_PUBLIC_KEY_INFO.cs View File

@ -0,0 +1,26 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CERT_PUBLIC_KEY_INFO
{
public IntPtr pszObjId;
public int agcbData;
public IntPtr agpbData;
public int pkcbData;
public IntPtr pkpbData;
public int pkcUnusedBits;
public CERT_PUBLIC_KEY_INFO(CertificateInfo info)
{
this.pszObjId = info.SubjectPublicKeyInfoAlgorithmpszObjId;
this.agcbData = info.SubjectPublicKeyInfoAlgorithmParameterscbData;
this.agpbData = info.SubjectPublicKeyInfoAlgorithmParameterspbData;
this.pkcbData = info.SubjectPublicKeyInfoPublicKeycbData;
this.pkpbData = info.SubjectPublicKeyInfoPublicKeypbData;
this.pkcUnusedBits = info.SubjectPublicKeyInfoPublicKeycUnusedBits;
}
}
}

+ 20
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CRYPT_KEY_PROV_INFO.cs View File

@ -0,0 +1,20 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
internal struct CRYPT_KEY_PROV_INFO
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pwszContainerName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwszProvName;
public int dwProvType;
public int dwFlags;
public int cProvParam;
public IntPtr rgProvParam;
public int dwKeySpec;
}
}

+ 16
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CertificateContext.cs View File

@ -0,0 +1,16 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateContext
{
public int dwCertEncodingType;
public IntPtr pbCertEncoded;
public int cbCertEncoded;
public IntPtr pCertInfo;
public IntPtr hCertStore;
}
}

+ 15
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CertificateExtension.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateExtension
{
public IntPtr pszObjId;
public int fCritical;
public int cbData;
public IntPtr pbData;
}
}

+ 37
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CertificateInfo.cs View File

@ -0,0 +1,37 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateInfo
{
public int dwVersion;
public int SerialNumbercbData;
public IntPtr SerialNumberpbData;
public IntPtr SignatureAlgorithmpszObjId;
public int SignatureAlgorithmParameterscbData;
public IntPtr SignatureAlgorithmParameterspbData;
public int IssuercbData;
public IntPtr IssuerpbData;
public long NotBefore;
public long NotAfter;
public int SubjectcbData;
public IntPtr SubjectpbData;
public IntPtr SubjectPublicKeyInfoAlgorithmpszObjId;
public int SubjectPublicKeyInfoAlgorithmParameterscbData;
public IntPtr SubjectPublicKeyInfoAlgorithmParameterspbData;
public int SubjectPublicKeyInfoPublicKeycbData;
public IntPtr SubjectPublicKeyInfoPublicKeypbData;
public int SubjectPublicKeyInfoPublicKeycUnusedBits;
public int IssuerUniqueIdcbData;
public IntPtr IssuerUniqueIdpbData;
public int IssuerUniqueIdcUnusedBits;
public int SubjectUniqueIdcbData;
public IntPtr SubjectUniqueIdpbData;
public int SubjectUniqueIdcUnusedBits;
public int cExtension;
public IntPtr rgExtension;
}
}

+ 13
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CertificateNameInfo.cs View File

@ -0,0 +1,13 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateNameInfo
{
public int cRDN;
public IntPtr rgRDN;
}
}

+ 14
- 0
B2B/TrustPay/com/hitrust/b2b/Security/CertificateNameValue.cs View File

@ -0,0 +1,14 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateNameValue
{
public int dwValueType;
public int cbData;
public IntPtr pbData;
}
}

+ 11
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/AuthType.cs View File

@ -0,0 +1,11 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public enum AuthType
{
Client = 1,
Server = 2
}
}

+ 1221
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/Certificate.cs
File diff suppressed because it is too large
View File


+ 239
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateChain.cs View File

@ -0,0 +1,239 @@
namespace com.hitrust.b2b.Security.Certificates
{
using com.hitrust.b2b.Security;
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
public class CertificateChain
{
private com.hitrust.b2b.Security.Certificates.Certificate m_Certificate;
private IntPtr m_Handle;
public CertificateChain(com.hitrust.b2b.Security.Certificates.Certificate cert) : this(cert, null)
{
}
public CertificateChain(com.hitrust.b2b.Security.Certificates.Certificate cert, CertificateStore additional) : this(cert, additional, CertificateChainOptions.Default)
{
}
public CertificateChain(com.hitrust.b2b.Security.Certificates.Certificate cert, CertificateStore additional, CertificateChainOptions options)
{
if (cert == null)
{
throw new ArgumentNullException();
}
IntPtr hAdditionalStore = (additional == null) ? IntPtr.Zero : additional.Handle;
ChainParameters pChainPara = new ChainParameters {
cbSize = Marshal.SizeOf(typeof(ChainParameters)),
RequestedUsagecUsageIdentifier = 0,
RequestedUsagedwType = 0,
RequestedUsagergpszUsageIdentifier = IntPtr.Zero
};
if (SspiProvider.CertGetCertificateChain(IntPtr.Zero, cert.Handle, IntPtr.Zero, hAdditionalStore, ref pChainPara, (int) options, IntPtr.Zero, ref this.m_Handle) == 0)
{
throw new CertificateException("Unable to find the certificate chain.");
}
this.m_Certificate = cert;
}
public virtual IAsyncResult BeginVerifyChain(string server, AuthType type, VerificationFlags flags, AsyncCallback callback, object asyncState)
{
CertificateVerificationResult state = new CertificateVerificationResult(this, server, type, flags, callback, asyncState);
if (!ThreadPool.QueueUserWorkItem(new WaitCallback(this.StartVerification), state))
{
throw new CertificateException("Could not schedule the certificate chain for verification.");
}
return state;
}
public virtual CertificateStatus EndVerifyChain(IAsyncResult ar)
{
CertificateVerificationResult result;
if (ar == null)
{
throw new ArgumentNullException();
}
try
{
result = (CertificateVerificationResult) ar;
}
catch
{
throw new ArgumentException();
}
if (result.Chain != this)
{
throw new ArgumentException();
}
if (result.HasEnded)
{
throw new InvalidOperationException();
}
if (result.ThrowException != null)
{
throw result.ThrowException;
}
result.HasEnded = true;
return result.Status;
}
~CertificateChain()
{
if (this.m_Handle != IntPtr.Zero)
{
SspiProvider.CertFreeCertificateChain(this.m_Handle);
this.m_Handle = IntPtr.Zero;
}
}
public virtual com.hitrust.b2b.Security.Certificates.Certificate[] GetCertificates()
{
ArrayList list = new ArrayList();
IntPtr handle = ((com.hitrust.b2b.Security.Certificates.Certificate) this.Certificate.Clone()).Handle;
CertificateStoreCollection store = this.Certificate.Store as CertificateStoreCollection;
if (store != null)
{
store = new CertificateStoreCollection(store);
}
else
{
store = new CertificateStoreCollection(new CertificateStore[0]);
store.AddStore(new CertificateStore(this.Certificate.m_Context.hCertStore, true));
}
store.AddStore(new CertificateStore("Root"));
IntPtr hCertStore = store.Handle;
while (handle != IntPtr.Zero)
{
list.Add(new com.hitrust.b2b.Security.Certificates.Certificate(handle, true));
int pdwFlags = 0;
handle = SspiProvider.CertGetIssuerCertificateFromStore(hCertStore, handle, IntPtr.Zero, ref pdwFlags);
}
return (com.hitrust.b2b.Security.Certificates.Certificate[]) list.ToArray(typeof(com.hitrust.b2b.Security.Certificates.Certificate));
}
protected void StartVerification(object state)
{
if (state != null)
{
CertificateVerificationResult result;
CertificateStatus status;
try
{
result = (CertificateVerificationResult) state;
}
catch
{
return;
}
try
{
status = this.VerifyChain(result.Server, result.Type, result.Flags);
}
catch (CertificateException exception)
{
result.VerificationCompleted(exception, CertificateStatus.OtherError);
return;
}
catch (Exception exception2)
{
result.VerificationCompleted(new CertificateException("Could not verify the certificate chain.", exception2), CertificateStatus.OtherError);
return;
}
result.VerificationCompleted(null, status);
}
}
public virtual CertificateStatus VerifyChain(string server, AuthType type)
{
return this.VerifyChain(server, type, VerificationFlags.None);
}
public virtual CertificateStatus VerifyChain(string server, AuthType type, VerificationFlags flags)
{
CertificateStatus otherError;
IntPtr zero = IntPtr.Zero;
IntPtr ptr = IntPtr.Zero;
try
{
if (server == null)
{
zero = IntPtr.Zero;
}
else
{
zero = Marshal.StringToHGlobalUni(server);
}
SslPolicyParameters structure = new SslPolicyParameters {
cbSize = Marshal.SizeOf(typeof(SslPolicyParameters)),
dwAuthType = (int) type,
pwszServerName = zero,
fdwChecks = (int) flags
};
ptr = Marshal.AllocHGlobal(structure.cbSize);
Marshal.StructureToPtr(structure, ptr, false);
ChainPolicyParameters pPolicyPara = new ChainPolicyParameters {
cbSize = Marshal.SizeOf(typeof(ChainPolicyParameters)),
dwFlags = (int) flags,
pvExtraPolicyPara = ptr
};
ChainPolicyStatus pPolicyStatus = new ChainPolicyStatus {
cbSize = Marshal.SizeOf(typeof(ChainPolicyStatus))
};
if (SspiProvider.CertVerifyCertificateChainPolicy(new IntPtr(4), this.m_Handle, ref pPolicyPara, ref pPolicyStatus) == 0)
{
throw new CertificateException("Unable to verify the certificate.");
}
if (Enum.IsDefined(typeof(CertificateStatus), pPolicyStatus.dwError))
{
return (CertificateStatus) pPolicyStatus.dwError;
}
otherError = CertificateStatus.OtherError;
}
finally
{
if (ptr != IntPtr.Zero)
{
Marshal.FreeHGlobal(ptr);
}
if (zero != IntPtr.Zero)
{
Marshal.FreeHGlobal(zero);
}
}
return otherError;
}
public virtual CertificateStatus VerifyChain(string server, AuthType type, VerificationFlags flags, byte[] crl)
{
CertificateStatus status = this.VerifyChain(server, type, flags);
if ((status != CertificateStatus.ValidCertificate) || (crl == null))
{
return status;
}
try
{
if (!this.m_Certificate.VerifyRevocation(crl))
{
return CertificateStatus.Revoked;
}
return status;
}
catch
{
return CertificateStatus.RevocationFailure;
}
}
protected com.hitrust.b2b.Security.Certificates.Certificate Certificate
{
get
{
return this.m_Certificate;
}
}
}
}

+ 19
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateChainOptions.cs View File

@ -0,0 +1,19 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public enum CertificateChainOptions
{
CacheOnlyUrlRetrieval = 4,
Default = 0,
DisableAuthRootAutoUpdate = 0x100,
DisablePass1QualityFiltering = 0x40,
ReturnLowerQualityContexts = 0x80,
RevocationCacheEndCert = 1,
RevocationCheckCacheOnly = -2147483648,
RevocationCheckChain = 0x20000000,
RevocationCheckChainExcludeRoot = 0x40000000,
RevocationCheckEndCert = 0x10000000
}
}

+ 26
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateException.cs View File

@ -0,0 +1,26 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
using System.Runtime.Serialization;
[Serializable]
public class CertificateException : Exception
{
public CertificateException()
{
}
public CertificateException(string message) : base(message)
{
}
protected CertificateException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public CertificateException(string message, Exception inner) : base(message, inner)
{
}
}
}

+ 26
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStatus.cs View File

@ -0,0 +1,26 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public enum CertificateStatus
{
Expired = -2146762495,
InvalidBasicConstraints = -2146869223,
InvalidChain = -2146762486,
InvalidNesting = -2146762494,
InvalidPurpose = -2146762490,
InvalidRole = -2146762493,
InvalidSignature = -2146869244,
NoCNMatch = -2146762481,
OtherError = -1,
ParentRevoked = -2146762484,
RevocationFailure = -2146762482,
RevocationServerOffline = -2146885613,
Revoked = -2146885616,
UntrustedRoot = -2146762487,
UntrustedTestRoot = -2146762483,
ValidCertificate = 0,
WrongUsage = -2146762480
}
}

+ 512
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStore.cs View File

@ -0,0 +1,512 @@
namespace com.hitrust.b2b.Security.Certificates
{
using Security;
using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
public class CertificateStore
{
public const string CAStore = "CA";
private IntPtr m_Handle;
public const string MyStore = "My";
public const string RootStore = "Root";
public const string SoftwarePublisherStore = "SPC";
public const string TrustStore = "Trust";
public const string UnTrustedStore = "Disallowed";
public CertificateStore()
{
this.m_Handle = SspiProvider.CertOpenStore(new IntPtr(2), 0x10001, IntPtr.Zero, 0, null);
if (this.m_Handle == IntPtr.Zero) {
throw new CertificateException("An error occurs while creating the store.");
}
}
public CertificateStore(CertificateStore store)
{
if (store == null) {
throw new ArgumentNullException();
}
this.InitStore(store.m_Handle, true);
}
public CertificateStore(IEnumerable certs) : this()
{
IEnumerator enumerator = certs.GetEnumerator();
while (enumerator.MoveNext()) {
this.AddCertificate((Certificate)enumerator.Current);
}
}
public CertificateStore(IntPtr handle) : this(handle, false) {}
public CertificateStore(string store) : this(StoreLocation.Users, store) {}
public CertificateStore(byte[] buffer, CertificateStoreType type)
{
DataBlob blob;
IntPtr ptr;
if (buffer == null) {
throw new ArgumentNullException();
}
blob = new DataBlob();
blob.cbData = buffer.Length;
blob.pbData = Marshal.AllocHGlobal(blob.cbData);
Marshal.Copy(buffer, 0, blob.pbData, buffer.Length);
if (type == CertificateStoreType.Pkcs7Message) {
ptr = new IntPtr(5);
} else {
ptr = new IntPtr(6);
}
this.m_Handle = SspiProvider.CertOpenStoreData(ptr, 0x10001, IntPtr.Zero, 0, ref blob);
Marshal.FreeHGlobal(blob.pbData);
if (this.m_Handle == IntPtr.Zero) {
throw new CertificateException("An error occurs while opening the store.");
}
}
public CertificateStore(StoreLocation location, string store)
{
if (store == null) {
throw new ArgumentNullException("The name of the store cannot be a null reference.");
}
this.m_Handle = SspiProvider.CertOpenStore(new IntPtr(9), 0, IntPtr.Zero, (int)location, store);
if (this.m_Handle == IntPtr.Zero) {
throw new CertificateException("An error occurs while opening the specified store.");
}
}
public CertificateStore(IntPtr handle, bool duplicate)
{
this.InitStore(handle, duplicate);
}
public void AddCertificate(Certificate cert)
{
if (cert == null) {
throw new ArgumentNullException();
}
if ((SspiProvider.CertAddCertificateContextToStore(this.Handle, cert.Handle, 1, IntPtr.Zero) == 0) && (Marshal.GetLastWin32Error() != -2146885627)) {
throw new CertificateException("An error occurs while adding the certificate to the store.");
}
}
public static CertificateStore CreateFromCerFile(string file)
{
if (file == null) {
throw new ArgumentNullException("The filename cannot be a null reference.");
}
IntPtr handle = SspiProvider.CertOpenStore(new IntPtr(7), 0x10001, IntPtr.Zero, 0, file);
if (handle == IntPtr.Zero) {
throw new CertificateException("An error occurs while opening the specified store.");
}
return new CertificateStore(handle);
}
public static CertificateStore CreateFromPfxFile(byte[] file, string password)
{
return CreateFromPfxFile(file, password, false);
}
public static CertificateStore CreateFromPfxFile(string file, string password)
{
return CreateFromPfxFile(GetFileContents(file), password);
}
public static CertificateStore CreateFromPfxFile(byte[] file, string password, bool exportable)
{
return CreateFromPfxFile(file, password, exportable, KeysetLocation.Default);
}
public static CertificateStore CreateFromPfxFile(string file, string password, bool exportable)
{
return CreateFromPfxFile(GetFileContents(file), password, exportable);
}
public static CertificateStore CreateFromPfxFile(byte[] file, string password, bool exportable, KeysetLocation location)
{
if ((password == null) || (file == null)) {
throw new ArgumentNullException("The arguments cannot be null references.");
}
DataBlob pPFX = new DataBlob {
cbData = file.Length
};
IntPtr destination = Marshal.AllocHGlobal(file.Length);
Marshal.Copy(file, 0, destination, file.Length);
pPFX.pbData = destination;
try {
if (SspiProvider.PFXIsPFXBlob(ref pPFX) == 0) {
throw new CertificateException("The specified file is not a PFX file.");
}
if (SspiProvider.PFXVerifyPassword(ref pPFX, password, 0) == 0) {
throw new CertificateException("The specified password is invalid.");
}
int dwFlags = (int)location;
if (exportable) {
dwFlags |= 1;
}
IntPtr handle = SspiProvider.PFXImportCertStore(ref pPFX, password, dwFlags);
if (handle.Equals(IntPtr.Zero)) {
throw new CertificateException("Unable to import the PFX file! [error code = " + Marshal.GetLastWin32Error() + "]");
}
return new CertificateStore(handle);
} finally {
Marshal.FreeHGlobal(destination);
}
}
public static CertificateStore CreateFromPfxFile(string file, string password, bool exportable, KeysetLocation location)
{
return CreateFromPfxFile(GetFileContents(file), password, exportable, location);
}
public void DeleteCertificate(Certificate cert)
{
if (cert == null) {
throw new ArgumentNullException();
}
Certificate certificate = this.FindCertificateByHash(cert.GetCertHash(HashType.SHA1), HashType.SHA1);
if (certificate == null) {
throw new CertificateException("The certificate could not be found in the store.");
}
if (SspiProvider.CertDeleteCertificateFromStore(certificate.Handle) == 0) {
throw new CertificateException("An error occurs while removing the certificate from the store.");
}
}
public Certificate[] EnumCertificates()
{
ArrayList list = new ArrayList();
for (Certificate certificate = this.FindCertificate(); certificate != null; certificate = this.FindCertificate(certificate)) {
list.Add(certificate);
}
return (Certificate[])list.ToArray(typeof(Certificate));
}
public Certificate[] EnumCertificates(string[] keyUsage)
{
ArrayList list = new ArrayList();
for (Certificate certificate = this.FindCertificateByUsage(keyUsage); certificate != null; certificate = this.FindCertificateByUsage(keyUsage, certificate)) {
list.Add(certificate);
}
return (Certificate[])list.ToArray(typeof(Certificate));
}
~CertificateStore()
{
if (this.Handle != IntPtr.Zero) {
SspiProvider.CertCloseStore(this.Handle, 0);
this.m_Handle = IntPtr.Zero;
}
}
public Certificate FindCertificate()
{
return this.FindCertificate(null);
}
public Certificate FindCertificate(Certificate previous)
{
IntPtr zero;
if (previous == null) {
zero = IntPtr.Zero;
} else {
zero = SspiProvider.CertDuplicateCertificateContext(previous.Handle);
}
IntPtr handle = SspiProvider.CertFindCertificateInStore(this.Handle, 1, 0, 0, IntPtr.Zero, zero);
if (handle.Equals(IntPtr.Zero)) {
return null;
}
return new Certificate(handle, this);
}
public Certificate FindCertificateByHash(byte[] hash)
{
return this.FindCertificateByHash(hash, HashType.SHA1);
}
public Certificate FindCertificateByHash(byte[] hash, HashType hashType)
{
int num;
if (hash == null) {
throw new ArgumentNullException();
}
if (hashType == HashType.SHA1) {
num = 0x10000;
} else if (hashType == HashType.MD5) {
num = 0x40000;
} else {
num = 0x10000;
}
DataBlob pvFindPara = new DataBlob {
cbData = hash.Length,
pbData = Marshal.AllocHGlobal(hash.Length)
};
Marshal.Copy(hash, 0, pvFindPara.pbData, hash.Length);
IntPtr handle = SspiProvider.CertFindDataBlobCertificateInStore(this.Handle, 0x10001, 0, num, ref pvFindPara, IntPtr.Zero);
Marshal.FreeHGlobal(pvFindPara.pbData);
if (handle == IntPtr.Zero) {
return null;
}
return new Certificate(handle);
}
public Certificate FindCertificateByKeyIdentifier(byte[] keyID)
{
if (keyID == null) {
throw new ArgumentNullException();
}
if (keyID.Length == 0) {
throw new ArgumentException();
}
DataBlob pvFindPara = new DataBlob {
cbData = keyID.Length,
pbData = Marshal.AllocHGlobal(keyID.Length)
};
Marshal.Copy(keyID, 0, pvFindPara.pbData, keyID.Length);
IntPtr handle = SspiProvider.CertFindDataBlobCertificateInStore(this.Handle, 0x10001, 0, 0xf0000, ref pvFindPara, IntPtr.Zero);
Marshal.FreeHGlobal(pvFindPara.pbData);
if (handle == IntPtr.Zero) {
return null;
}
return new Certificate(handle);
}
public Certificate FindCertificateBySubjectName(string name)
{
return this.FindCertificateBySubjectName(name, null);
}
public Certificate FindCertificateBySubjectName(string name, Certificate previous)
{
IntPtr ptr;
if (name == null) {
throw new ArgumentNullException();
}
if (name.Length == 0) {
throw new ArgumentException();
}
IntPtr zero = IntPtr.Zero;
if (previous == null) {
ptr = IntPtr.Zero;
} else {
ptr = SspiProvider.CertDuplicateCertificateContext(previous.Handle);
}
DataBlob pvFindPara = new DataBlob();
if (SspiProvider.CertStrToName(0x10001, name, 3, IntPtr.Zero, IntPtr.Zero, ref pvFindPara.cbData, IntPtr.Zero) == 0) {
throw new CertificateException("Could not encode the specified string. [is the string a valid X500 string?]");
}
pvFindPara.pbData = Marshal.AllocHGlobal(pvFindPara.cbData);
try {
if (SspiProvider.CertStrToName(0x10001, name, 3, IntPtr.Zero, pvFindPara.pbData, ref pvFindPara.cbData, IntPtr.Zero) == 0) {
throw new CertificateException("Could not encode the specified string.");
}
zero = SspiProvider.CertFindDataBlobCertificateInStore(this.Handle, 0x10001, 0, 0x20007, ref pvFindPara, ptr);
} finally {
Marshal.FreeHGlobal(pvFindPara.pbData);
}
if (zero == IntPtr.Zero) {
return null;
}
return new Certificate(zero);
}
public Certificate FindCertificateBySubjectString(string subject)
{
return this.FindCertificateBySubjectString(subject, null);
}
public Certificate FindCertificateBySubjectString(string subject, Certificate previous)
{
IntPtr zero;
if (subject == null) {
throw new ArgumentNullException();
}
if (subject.Length == 0) {
throw new ArgumentException();
}
if (previous == null) {
zero = IntPtr.Zero;
} else {
zero = SspiProvider.CertDuplicateCertificateContext(previous.Handle);
}
IntPtr handle = SspiProvider.CertFindStringCertificateInStore(this.Handle, 0x10001, 0, 0x80007, subject, zero);
if (handle == IntPtr.Zero) {
return null;
}
return new Certificate(handle);
}
public Certificate FindCertificateByUsage(string[] keyUsage)
{
return this.FindCertificateByUsage(keyUsage, null);
}
public Certificate FindCertificateByUsage(string[] keyUsage, Certificate previous)
{
IntPtr zero;
if (keyUsage == null) {
throw new ArgumentNullException();
}
if (keyUsage.Length == 0) {
throw new ArgumentException();
}
int cb = 0;
for (int i = 0; i < keyUsage.Length; i++) {
if ((keyUsage[i] == null) || (keyUsage[i].Length == 0)) {
throw new ArgumentException();
}
cb += keyUsage[i].Length + 1;
}
IntPtr hglobal = Marshal.AllocHGlobal(cb);
IntPtr ptr = Marshal.AllocHGlobal((int)(IntPtr.Size * keyUsage.Length));
cb = 0;
IntPtr destination = hglobal;
for (int j = 0; j < keyUsage.Length; j++) {
Marshal.Copy(Encoding.ASCII.GetBytes(keyUsage[j] + "\0"), 0, destination, keyUsage[j].Length + 1);
Marshal.WriteIntPtr(ptr, j * IntPtr.Size, destination);
destination = new IntPtr((hglobal.ToInt64() + keyUsage[j].Length) + 1L);
}
TrustListUsage pvFindPara = new TrustListUsage {
cUsageIdentifier = keyUsage.Length,
rgpszUsageIdentifier = ptr
};
if (previous == null) {
zero = IntPtr.Zero;
} else {
zero = SspiProvider.CertDuplicateCertificateContext(previous.Handle);
}
IntPtr handle = SspiProvider.CertFindUsageCertificateInStore(this.Handle, 0x10001, 0, 0xa0000, ref pvFindPara, zero);
Marshal.FreeHGlobal(ptr);
Marshal.FreeHGlobal(hglobal);
if (handle.Equals(IntPtr.Zero)) {
return null;
}
return new Certificate(handle, this);
}
private byte[] GetCerBuffer(CertificateStoreType type)
{
byte[] buffer2;
DataBlob pvSaveToPara = new DataBlob();
try {
pvSaveToPara.cbData = 0;
pvSaveToPara.pbData = IntPtr.Zero;
if (SspiProvider.CertSaveStore(this.Handle, 0x10001, (int)type, 2, ref pvSaveToPara, 0) == 0) {
throw new CertificateException("Unable to get the certificate data.");
}
pvSaveToPara.pbData = Marshal.AllocHGlobal(pvSaveToPara.cbData);
if (SspiProvider.CertSaveStore(this.Handle, 0x10001, (int)type, 2, ref pvSaveToPara, 0) == 0) {
throw new CertificateException("Unable to get the certificate data.");
}
byte[] destination = new byte[pvSaveToPara.cbData];
Marshal.Copy(pvSaveToPara.pbData, destination, 0, pvSaveToPara.cbData);
buffer2 = destination;
} finally {
if (pvSaveToPara.pbData != IntPtr.Zero) {
Marshal.FreeHGlobal(pvSaveToPara.pbData);
}
}
return buffer2;
}
internal static byte[] GetFileContents(string file)
{
byte[] buffer;
if (file == null) {
throw new ArgumentNullException();
}
try {
FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
buffer = new byte[stream.Length];
for (int i = stream.Read(buffer, 0, buffer.Length); i < stream.Length; i += stream.Read(buffer, i, buffer.Length - i)) {}
stream.Close();
} catch (Exception exception) {
throw new IOException("An error occurs while reading from the file.", exception);
}
return buffer;
}
private byte[] GetPfxBuffer(string password, bool exportPrivateKeys)
{
byte[] buffer2;
if (password == null) {
throw new ArgumentNullException();
}
DataBlob pPFX = new DataBlob();
try {
pPFX.pbData = IntPtr.Zero;
pPFX.cbData = 0;
if (SspiProvider.PFXExportCertStoreEx(this.Handle, ref pPFX, password, IntPtr.Zero, exportPrivateKeys ? 4 : 0) == 0) {
throw new CertificateException("Could not export the certificate store.");
}
pPFX.pbData = Marshal.AllocHGlobal(pPFX.cbData);
if (SspiProvider.PFXExportCertStoreEx(this.Handle, ref pPFX, password, IntPtr.Zero, exportPrivateKeys ? 4 : 0) == 0) {
throw new CertificateException("Could not export the certificate store.");
}
byte[] destination = new byte[pPFX.cbData];
Marshal.Copy(pPFX.pbData, destination, 0, destination.Length);
buffer2 = destination;
} finally {
if (pPFX.pbData != IntPtr.Zero) {
Marshal.FreeHGlobal(pPFX.pbData);
}
}
return buffer2;
}
protected void InitStore(IntPtr handle, bool duplicate)
{
if (handle == IntPtr.Zero) {
throw new ArgumentException("Invalid certificate store handle!");
}
if (duplicate) {
this.m_Handle = SspiProvider.CertDuplicateStore(handle);
} else {
this.m_Handle = handle;
}
}
private void SaveToFile(byte[] buffer, string filename)
{
if ((filename == null) || (buffer == null)) {
throw new ArgumentNullException();
}
try {
FileStream stream = File.Open(filename, FileMode.CreateNew, FileAccess.Write, FileShare.None);
stream.Write(buffer, 0, buffer.Length);
stream.Close();
} catch (Exception exception) {
throw new IOException("Could not write data to file.", exception);
}
}
public byte[] ToCerBuffer(CertificateStoreType type)
{
return this.GetCerBuffer(type);
}
public void ToCerFile(string filename, CertificateStoreType type)
{
this.SaveToFile(this.GetCerBuffer(type), filename);
}
public byte[] ToPfxBuffer(string password, bool exportPrivateKeys)
{
return this.GetPfxBuffer(password, exportPrivateKeys);
}
public void ToPfxFile(string filename, string password, bool exportPrivateKeys)
{
this.SaveToFile(this.GetPfxBuffer(password, exportPrivateKeys), filename);
}
public IntPtr Handle
{
get { return this.m_Handle; }
}
}
}

+ 79
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStoreCollection.cs View File

@ -0,0 +1,79 @@
namespace com.hitrust.b2b.Security.Certificates
{
using com.hitrust.b2b.Security;
using System;
using System.Collections;
public class CertificateStoreCollection : CertificateStore
{
private ArrayList m_Stores;
public CertificateStoreCollection(CertificateStore[] stores) : base(SspiProvider.CertOpenStore(new IntPtr(11), 0, IntPtr.Zero, 0, null), false)
{
if (stores == null)
{
throw new ArgumentNullException();
}
for (int i = 0; i < stores.Length; i++)
{
if (stores[i].ToString() == this.ToString())
{
throw new ArgumentException("A certificate store collection cannot hold other certificate store collections.");
}
}
for (int j = 0; j < stores.Length; j++)
{
if (SspiProvider.CertAddStoreToCollection(base.Handle, stores[j].Handle, 0, 0) == 0)
{
throw new CertificateException("Could not add the store to the collection.");
}
}
this.m_Stores = new ArrayList();
this.m_Stores.AddRange(stores);
}
public CertificateStoreCollection(CertificateStoreCollection collection) : base(SspiProvider.CertOpenStore(new IntPtr(11), 0, IntPtr.Zero, 0, null), false)
{
if (collection == null)
{
throw new ArgumentNullException();
}
this.m_Stores = new ArrayList(collection.m_Stores);
for (int i = 0; i < this.m_Stores.Count; i++)
{
if (SspiProvider.CertAddStoreToCollection(base.Handle, ((CertificateStore) this.m_Stores[i]).Handle, 0, 0) == 0)
{
throw new CertificateException("Could not add the store to the collection.");
}
}
}
public void AddStore(CertificateStore store)
{
if (store == null)
{
throw new ArgumentNullException();
}
if (store.ToString() == this.ToString())
{
throw new ArgumentException("A certificate store collection cannot hold other certificate store collections.");
}
if (SspiProvider.CertAddStoreToCollection(base.Handle, store.Handle, 0, 0) == 0)
{
throw new CertificateException("Could not add the store to the collection.");
}
this.m_Stores.Add(store);
}
public void RemoveStore(CertificateStore store)
{
if (store == null)
{
throw new ArgumentNullException();
}
SspiProvider.CertRemoveStoreFromCollection(base.Handle, store.Handle);
this.m_Stores.Remove(store);
}
}
}

+ 11
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateStoreType.cs View File

@ -0,0 +1,11 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public enum CertificateStoreType
{
Pkcs7Message = 2,
SerializedStore = 1
}
}

+ 144
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/CertificateVerificationResult.cs View File

@ -0,0 +1,144 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
using System.Threading;
internal class CertificateVerificationResult : IAsyncResult
{
private object m_AsyncState;
private AsyncCallback m_Callback;
private CertificateChain m_Chain;
private VerificationFlags m_Flags;
private bool m_HasEnded;
private bool m_IsCompleted;
private string m_Server;
private CertificateStatus m_Status;
private Exception m_ThrowException;
private AuthType m_Type;
private ManualResetEvent m_WaitHandle;
public CertificateVerificationResult(CertificateChain chain, string server, AuthType type, VerificationFlags flags, AsyncCallback callback, object asyncState)
{
this.m_Chain = chain;
this.m_Server = server;
this.m_Type = type;
this.m_Flags = flags;
this.m_AsyncState = asyncState;
this.m_Callback = callback;
this.m_WaitHandle = null;
this.m_HasEnded = false;
}
internal void VerificationCompleted(Exception error, CertificateStatus status)
{
this.m_ThrowException = error;
this.m_Status = status;
this.m_IsCompleted = true;
if (this.m_Callback != null)
{
this.m_Callback(this);
}
if (this.m_WaitHandle != null)
{
this.m_WaitHandle.Set();
}
}
public object AsyncState
{
get
{
return this.m_AsyncState;
}
}
public WaitHandle AsyncWaitHandle
{
get
{
if (this.m_WaitHandle == null)
{
this.m_WaitHandle = new ManualResetEvent(false);
}
return this.m_WaitHandle;
}
}
public CertificateChain Chain
{
get
{
return this.m_Chain;
}
}
public bool CompletedSynchronously
{
get
{
return false;
}
}
public VerificationFlags Flags
{
get
{
return this.m_Flags;
}
}
public bool HasEnded
{
get
{
return this.m_HasEnded;
}
set
{
this.m_HasEnded = value;
}
}
public bool IsCompleted
{
get
{
return this.m_IsCompleted;
}
}
public string Server
{
get
{
return this.m_Server;
}
}
public CertificateStatus Status
{
get
{
return this.m_Status;
}
}
public Exception ThrowException
{
get
{
return this.m_ThrowException;
}
}
public AuthType Type
{
get
{
return this.m_Type;
}
}
}
}

+ 131
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/DistinguishedName.cs View File

@ -0,0 +1,131 @@
namespace com.hitrust.b2b.Security.Certificates
{
using com.hitrust.b2b.Security;
using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
public class DistinguishedName
{
private ArrayList m_List;
public DistinguishedName()
{
this.m_List = new ArrayList();
}
internal DistinguishedName(CertificateNameInfo cni) : this()
{
this.Initialize(cni);
}
internal DistinguishedName(IntPtr input, int length) : this()
{
int pcbStructInfo = 0;
SspiProvider.CryptDecodeObject(0x10001, new IntPtr(20), input, length, 0, IntPtr.Zero, ref pcbStructInfo);
if (pcbStructInfo <= 0)
{
throw new CertificateException("Unable to decode the name of the certificate.");
}
IntPtr pvStructInfo = Marshal.AllocHGlobal(pcbStructInfo);
if (SspiProvider.CryptDecodeObject(0x10001, new IntPtr(20), input, length, 0, pvStructInfo, ref pcbStructInfo) == 0)
{
throw new CertificateException("Unable to decode the name of the certificate.");
}
try
{
CertificateNameInfo cni = (CertificateNameInfo) Marshal.PtrToStructure(pvStructInfo, typeof(CertificateNameInfo));
this.Initialize(cni);
}
catch (CertificateException exception)
{
throw exception;
}
catch (Exception exception2)
{
throw new CertificateException("Could not get the certificate distinguished name.", exception2);
}
finally
{
if (pvStructInfo != IntPtr.Zero)
{
Marshal.FreeHGlobal(pvStructInfo);
}
}
}
public int Add(NameAttribute attribute)
{
return this.m_List.Add(attribute);
}
public void Clear()
{
this.m_List.Clear();
}
public bool Contains(NameAttribute value)
{
return this.m_List.Contains(value);
}
public int IndexOf(NameAttribute value)
{
return this.m_List.IndexOf(value);
}
private void Initialize(CertificateNameInfo cni)
{
if (cni.cRDN <= 0)
{
throw new CertificateException("Certificate does not have a subject relative distinguished name.");
}
for (int i = 0; i < cni.cRDN; i++)
{
RelativeDistinguishedName name = (RelativeDistinguishedName) Marshal.PtrToStructure(new IntPtr(cni.rgRDN.ToInt64() + (i * Marshal.SizeOf(typeof(RelativeDistinguishedName)))), typeof(RelativeDistinguishedName));
for (int j = 0; j < name.cRDNAttr; j++)
{
RdnAttribute attribute = (RdnAttribute) Marshal.PtrToStructure(new IntPtr(name.rgRDNAttr.ToInt64() + (j * Marshal.SizeOf(typeof(RdnAttribute)))), typeof(RdnAttribute));
this.m_List.Add(new NameAttribute(Marshal.PtrToStringAnsi(attribute.pszObjId), Marshal.PtrToStringUni(attribute.pbData)));
}
}
}
public void Insert(int index, NameAttribute value)
{
this.m_List.Insert(index, value);
}
public void Remove(NameAttribute value)
{
this.m_List.Remove(value);
}
public void RemoveAt(int index)
{
this.m_List.RemoveAt(index);
}
public int Count
{
get
{
return this.m_List.Count;
}
}
public NameAttribute this[int index]
{
get
{
return (NameAttribute) this.m_List[index];
}
set
{
this.m_List[index] = value;
}
}
}
}

+ 148
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/DistinguishedNameList.cs View File

@ -0,0 +1,148 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
using System.Collections;
using System.Reflection;
public class DistinguishedNameList : IEnumerable, ICloneable
{
private ArrayList m_List;
public DistinguishedNameList()
{
this.m_List = new ArrayList();
}
internal DistinguishedNameList(ArrayList state)
{
if (state == null)
{
throw new ArgumentNullException();
}
this.m_List = (ArrayList) state.Clone();
}
public int Add(DistinguishedName value)
{
if (value == null)
{
throw new ArgumentNullException();
}
return this.m_List.Add(value);
}
public void Clear()
{
this.m_List.Clear();
}
public object Clone()
{
return new DistinguishedNameList(this.m_List);
}
public bool Contains(DistinguishedName value)
{
if (value == null)
{
throw new ArgumentNullException();
}
return this.m_List.Contains(value);
}
public void CopyTo(Array array, int index)
{
this.m_List.CopyTo(array, index);
}
public IEnumerator GetEnumerator()
{
return this.m_List.GetEnumerator();
}
public int IndexOf(DistinguishedName value)
{
if (value == null)
{
throw new ArgumentNullException();
}
return this.m_List.IndexOf(value);
}
public void Insert(int index, DistinguishedName value)
{
if (value == null)
{
throw new ArgumentNullException();
}
this.m_List.Insert(index, value);
}
public void Remove(DistinguishedName value)
{
this.m_List.Remove(value);
}
public void RemoveAt(int index)
{
this.m_List.RemoveAt(index);
}
public int Count
{
get
{
return this.m_List.Count;
}
}
public bool IsFixedSize
{
get
{
return this.m_List.IsFixedSize;
}
}
public bool IsReadOnly
{
get
{
return this.m_List.IsReadOnly;
}
}
public bool IsSynchronized
{
get
{
return this.m_List.IsSynchronized;
}
}
public DistinguishedName this[int index]
{
get
{
return (DistinguishedName) this.m_List[index];
}
set
{
if (value == null)
{
throw new ArgumentNullException();
}
this.m_List[index] = value;
}
}
public object SyncRoot
{
get
{
return this.m_List.SyncRoot;
}
}
}
}

+ 19
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/Extension.cs View File

@ -0,0 +1,19 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public class Extension
{
public bool Critical;
public byte[] EncodedValue;
public string ObjectID;
public Extension(string oid, bool critical, byte[] val)
{
this.ObjectID = oid;
this.Critical = critical;
this.EncodedValue = val;
}
}
}

+ 12
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/HashType.cs View File

@ -0,0 +1,12 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public enum HashType
{
Default = 3,
MD5 = 4,
SHA1 = 3
}
}

+ 17
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/KeyUsage.cs View File

@ -0,0 +1,17 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
[Flags]
public enum KeyUsage
{
CrlSign = 2,
DataEncipherment = 0x10,
DigitalSignature = 0x80,
KeyAgreement = 8,
KeyCertSign = 4,
KeyEncipherment = 0x20,
NonRepudiation = 0x40
}
}

+ 12
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/KeysetLocation.cs View File

@ -0,0 +1,12 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public enum KeysetLocation
{
CurrentUser = 0x1000,
Default = 0,
LocalMachine = 0x20
}
}

+ 65
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/NameAttribute.cs View File

@ -0,0 +1,65 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct NameAttribute
{
public string ObjectID;
public string Value;
public NameAttribute(string oid, string val)
{
this.ObjectID = oid;
this.Value = val;
}
public override bool Equals(object obj)
{
try
{
NameAttribute attribute = (NameAttribute) obj;
return ((attribute.ObjectID == this.ObjectID) && (attribute.Value == this.Value));
}
catch
{
return false;
}
}
public override int GetHashCode()
{
if ((this.ObjectID == null) && (this.Value == null))
{
return 0;
}
if (this.ObjectID == null)
{
return this.Value.GetHashCode();
}
if (this.Value == null)
{
return this.ObjectID.GetHashCode();
}
return (this.Value.GetHashCode() ^ this.ObjectID.GetHashCode());
}
public override string ToString()
{
if ((this.ObjectID == null) && (this.Value == null))
{
return "N/A: N/A";
}
if (this.ObjectID == null)
{
return ("N/A: " + this.Value);
}
if (this.Value == null)
{
return (this.ObjectID + ": N/A");
}
return (this.ObjectID + ": " + this.Value);
}
}
}

+ 18
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/StoreLocation.cs View File

@ -0,0 +1,18 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
public enum StoreLocation
{
CurrentService = 0x40000,
CurrentUser = 0x60000,
CurrentUserGroupPolicy = 0x70000,
LocalMachine = 0x20000,
LocalMachineEnterprise = 0x90000,
LocalMachineGroupPolicy = 0x80000,
Services = 0x50000,
Unknown = 0,
Users = 0x10000
}
}

+ 27
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Certificates/VerificationFlags.cs View File

@ -0,0 +1,27 @@
namespace com.hitrust.b2b.Security.Certificates
{
using System;
[Flags]
public enum VerificationFlags
{
AllowTestroot = 0x8000,
AllowUnknownCA = 0x10,
IgnoreAllRevUnknown = 0xf00,
IgnoreAllTimeChecks = 7,
IgnoreCARevUnknown = 0x400,
IgnoreCtlTimeNotValid = 2,
IgnoreEndRevUnknown = 0x100,
IgnoreInvalidBasicContraints = 8,
IgnoreInvalidName = 0x40,
IgnoreInvalidPolicy = 0x80,
IgnoreRootRevUnknown = 0x800,
IgnoreSignerRevUnknown = 0x200,
IgnoreTimeNotNested = 4,
IgnoreTimeNotValid = 1,
IgnoreWrongUsage = 0x20,
None = 0,
TrustTestroot = 0x4000
}
}

+ 15
- 0
B2B/TrustPay/com/hitrust/b2b/Security/ChainParameters.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct ChainParameters
{
public int cbSize;
public int RequestedUsagedwType;
public int RequestedUsagecUsageIdentifier;
public IntPtr RequestedUsagergpszUsageIdentifier;
}
}

+ 14
- 0
B2B/TrustPay/com/hitrust/b2b/Security/ChainPolicyParameters.cs View File

@ -0,0 +1,14 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct ChainPolicyParameters
{
public int cbSize;
public int dwFlags;
public IntPtr pvExtraPolicyPara;
}
}

+ 16
- 0
B2B/TrustPay/com/hitrust/b2b/Security/ChainPolicyStatus.cs View File

@ -0,0 +1,16 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct ChainPolicyStatus
{
public int cbSize;
public int dwError;
public int lChainIndex;
public int lElementIndex;
public IntPtr pvExtraPolicyStatus;
}
}

+ 43
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/ARCFourManaged.cs View File

@ -0,0 +1,43 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
using System.Security.Cryptography;
public sealed class ARCFourManaged : RC4
{
private bool m_IsDisposed = false;
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
{
if (this.m_IsDisposed)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (rgbKey == null)
{
throw new ArgumentNullException("Key is a null reference.");
}
if ((rgbKey.Length == 0) || (rgbKey.Length > 0x100))
{
throw new CryptographicException("Invalid Key.");
}
if ((rgbIV != null) && (rgbIV.Length > 1))
{
throw new CryptographicException("Invalid Initialization Vector.");
}
return new ARCFourManagedTransform(rgbKey);
}
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
{
return this.CreateDecryptor(rgbKey, rgbIV);
}
protected override void Dispose(bool disposing)
{
base.Dispose(true);
this.m_IsDisposed = true;
}
}
}

+ 138
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/ARCFourManagedTransform.cs View File

@ -0,0 +1,138 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
using System.Security.Cryptography;
internal sealed class ARCFourManagedTransform : ICryptoTransform, IDisposable
{
private bool m_Disposed;
private byte m_Index1;
private byte m_Index2;
private byte[] m_Key;
private int m_KeyLen;
private byte[] m_Permutation;
public ARCFourManagedTransform(byte[] key)
{
this.m_Key = (byte[]) key.Clone();
this.m_KeyLen = key.Length;
this.m_Permutation = new byte[0x100];
this.m_Disposed = false;
this.Init();
}
public void Dispose()
{
Array.Clear(this.m_Key, 0, this.m_Key.Length);
Array.Clear(this.m_Permutation, 0, this.m_Permutation.Length);
this.m_Index1 = 0;
this.m_Index2 = 0;
this.m_Disposed = true;
try
{
GC.SuppressFinalize(this);
}
catch
{
}
}
~ARCFourManagedTransform()
{
this.Dispose();
}
private void Init()
{
for (int i = 0; i < 0x100; i++)
{
this.m_Permutation[i] = (byte) i;
}
this.m_Index1 = 0;
this.m_Index2 = 0;
int index = 0;
for (int j = 0; j < 0x100; j++)
{
index = ((index + this.m_Permutation[j]) + this.m_Key[j % this.m_KeyLen]) % 0x100;
byte num = this.m_Permutation[j];
this.m_Permutation[j] = this.m_Permutation[index];
this.m_Permutation[index] = num;
}
}
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
if (this.m_Disposed)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if ((inputBuffer == null) || (outputBuffer == null))
{
throw new ArgumentNullException();
}
if (((inputOffset < 0) || (outputOffset < 0)) || (((inputOffset + inputCount) > inputBuffer.Length) || ((outputOffset + inputCount) > outputBuffer.Length)))
{
throw new ArgumentOutOfRangeException();
}
int num3 = inputOffset + inputCount;
while (inputOffset < num3)
{
this.m_Index1 = (byte) ((this.m_Index1 + 1) % 0x100);
this.m_Index2 = (byte) ((this.m_Index2 + this.m_Permutation[this.m_Index1]) % 0x100);
byte num2 = this.m_Permutation[this.m_Index1];
this.m_Permutation[this.m_Index1] = this.m_Permutation[this.m_Index2];
this.m_Permutation[this.m_Index2] = num2;
byte index = (byte) ((this.m_Permutation[this.m_Index1] + this.m_Permutation[this.m_Index2]) % 0x100);
outputBuffer[outputOffset] = (byte) (inputBuffer[inputOffset] ^ this.m_Permutation[index]);
inputOffset++;
outputOffset++;
}
return inputCount;
}
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
if (this.m_Disposed)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
byte[] outputBuffer = new byte[inputCount];
this.TransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, 0);
this.Init();
return outputBuffer;
}
public bool CanReuseTransform
{
get
{
return true;
}
}
public bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
public int InputBlockSize
{
get
{
return 1;
}
}
public int OutputBlockSize
{
get
{
return 1;
}
}
}
}

+ 13
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/CryptoAlgorithm.cs View File

@ -0,0 +1,13 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
internal enum CryptoAlgorithm
{
RC4 = 0x6801,
Rijndael128 = 0x660e,
Rijndael192 = 0x660f,
Rijndael256 = 0x6610
}
}

+ 11
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/CryptoMethod.cs View File

@ -0,0 +1,11 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
internal enum CryptoMethod
{
Encrypt,
Decrypt
}
}

+ 11
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/CryptoProvider.cs View File

@ -0,0 +1,11 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
internal enum CryptoProvider
{
RsaAes = 0x18,
RsaFull = 1
}
}

+ 15
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/PUBLICKEYSTRUC.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct PUBLICKEYSTRUC
{
public byte bType;
public byte bVersion;
public short reserved;
public IntPtr aiKeyAlg;
}
}

+ 11
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/ProtectionType.cs View File

@ -0,0 +1,11 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
public enum ProtectionType
{
LocalMachine,
CurrentUser
}
}

+ 112
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/RC4.cs View File

@ -0,0 +1,112 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using System;
using System.Security.Cryptography;
public abstract class RC4 : SymmetricAlgorithm
{
private RNGCryptoServiceProvider m_RNG;
protected RC4()
{
base.KeySizeValue = 0x80;
}
public new static RC4 Create()
{
return Create("ARCFOUR");
}
public new static RC4 Create(string AlgName)
{
RC4 rc = null;
try {
if ((AlgName.ToUpper() == "RC4") || (AlgName.ToLower() == "org.mentalis.security.cryptography.rc4cryptoserviceprovider")) {
return new RC4CryptoServiceProvider();
}
if (!(AlgName.ToUpper() == "ARCFOUR") && !(AlgName.ToLower() == "org.mentalis.security.cryptography.arcfourmanaged")) {
return null;
}
rc = new ARCFourManaged();
} catch {}
return rc;
}
public override void GenerateIV() {}
public override void GenerateKey()
{
byte[] data = new byte[this.KeySize / 8];
this.GetRNGCSP().GetBytes(data);
this.Key = data;
}
protected RNGCryptoServiceProvider GetRNGCSP()
{
if (this.m_RNG == null) {
this.m_RNG = new RNGCryptoServiceProvider();
}
return this.m_RNG;
}
public override int BlockSize
{
get { return 8; }
set
{
if ((value != 8) && (value != 0)) {
throw new CryptographicException("RC4 is a stream cipher, not a block cipher.");
}
}
}
public override int FeedbackSize
{
get { throw new CryptographicException("RC4 doesn't use the feedback size property."); }
set { throw new CryptographicException("RC4 doesn't use the feedback size property."); }
}
public override byte[] IV
{
get { return new byte[1]; }
set
{
if ((value != null) && (value.Length > 1)) {
throw new CryptographicException("RC4 doesn't use an Initialization Vector.");
}
}
}
public override KeySizes[] LegalBlockSizes
{
get { return new KeySizes[] {new KeySizes(8, 8, 0)}; }
}
public override KeySizes[] LegalKeySizes
{
get { return new KeySizes[] {new KeySizes(8, 0x800, 8)}; }
}
public override CipherMode Mode
{
get { return CipherMode.OFB; }
set
{
if (value != CipherMode.OFB) {
throw new CryptographicException("RC4 only supports OFB.");
}
}
}
public override PaddingMode Padding
{
get { return PaddingMode.None; }
set
{
if (value != PaddingMode.None) {
throw new CryptographicException("RC4 is a stream cipher, not a block cipher.");
}
}
}
}
}

+ 236
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/RC4CryptoServiceProvider.cs View File

@ -0,0 +1,236 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using com.hitrust.b2b.Security;
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
public sealed class RC4CryptoServiceProvider : RC4
{
private bool m_Disposed;
private ARCFourManaged m_Managed;
private int m_MaxLen;
private int m_MinLen;
private int m_Provider = 0;
public RC4CryptoServiceProvider()
{
if ((SspiProvider.CryptAcquireContext(ref this.m_Provider, IntPtr.Zero, null, 1, 0) == 0) && (Marshal.GetLastWin32Error() == -2146893802))
{
SspiProvider.CryptAcquireContext(ref this.m_Provider, IntPtr.Zero, null, 1, 8);
}
if (this.m_Provider != 0)
{
int dwFlags = 1;
bool flag = false;
IntPtr pbData = Marshal.AllocHGlobal(100);
do
{
int pdwDataLen = 100;
if (SspiProvider.CryptGetProvParam(this.m_Provider, 0x16, pbData, ref pdwDataLen, dwFlags) == 0)
{
break;
}
dwFlags = 0;
com.hitrust.b2b.Security.PROV_ENUMALGS_EX prov_enumalgs_ex = (com.hitrust.b2b.Security.PROV_ENUMALGS_EX) Marshal.PtrToStructure(pbData, typeof(com.hitrust.b2b.Security.PROV_ENUMALGS_EX));
if (prov_enumalgs_ex.aiAlgid == 0x6801)
{
flag = true;
this.m_MinLen = prov_enumalgs_ex.dwMinLen;
this.m_MaxLen = prov_enumalgs_ex.dwMaxLen;
}
}
while (!flag);
Marshal.FreeHGlobal(pbData);
if (!flag)
{
SspiProvider.CryptReleaseContext(this.m_Provider, 0);
this.m_Provider = 0;
}
}
this.m_Managed = new ARCFourManaged();
}
private bool CanUseUnmanaged(int keySize)
{
return (((this.m_Provider != 0) && (keySize >= this.m_MinLen)) && (keySize <= this.m_MaxLen));
}
public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
{
if (this.m_Disposed)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (rgbKey == null)
{
throw new ArgumentNullException("Key is a null reference.");
}
if ((rgbKey.Length == 0) || (rgbKey.Length > 0x100))
{
throw new CryptographicException("Invalid Key.");
}
if ((rgbIV != null) && (rgbIV.Length > 1))
{
throw new CryptographicException("Invalid Initialization Vector.");
}
try
{
if (this.CanUseUnmanaged(rgbKey.Length * 8))
{
return new RC4UnmanagedTransform(rgbKey);
}
}
catch
{
}
return this.m_Managed.CreateDecryptor(rgbKey, rgbIV);
}
public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
{
return this.CreateDecryptor(rgbKey, rgbIV);
}
private void CurrentDispose()
{
if (!this.m_Disposed)
{
this.m_Disposed = true;
if (this.m_Managed != null)
{
this.m_Managed.Clear();
this.m_Managed = null;
}
if (this.m_Provider != 0)
{
SspiProvider.CryptReleaseContext(this.m_Provider, 0);
this.m_Provider = 0;
}
try
{
GC.SuppressFinalize(this);
}
catch
{
}
}
}
~RC4CryptoServiceProvider()
{
this.CurrentDispose();
}
public override void GenerateIV()
{
this.m_Managed.GenerateIV();
}
public override void GenerateKey()
{
this.m_Managed.GenerateKey();
}
public override int BlockSize
{
get
{
return this.m_Managed.BlockSize;
}
set
{
this.m_Managed.BlockSize = value;
}
}
public override int FeedbackSize
{
get
{
return this.m_Managed.FeedbackSize;
}
set
{
this.m_Managed.FeedbackSize = value;
}
}
public override byte[] IV
{
get
{
return this.m_Managed.IV;
}
set
{
this.m_Managed.IV = value;
}
}
public override byte[] Key
{
get
{
return this.m_Managed.Key;
}
set
{
this.m_Managed.Key = value;
}
}
public override int KeySize
{
get
{
return this.m_Managed.KeySize;
}
set
{
this.m_Managed.KeySize = value;
}
}
public override KeySizes[] LegalBlockSizes
{
get
{
return this.m_Managed.LegalBlockSizes;
}
}
public override KeySizes[] LegalKeySizes
{
get
{
return this.m_Managed.LegalKeySizes;
}
}
public override CipherMode Mode
{
get
{
return this.m_Managed.Mode;
}
set
{
this.m_Managed.Mode = value;
}
}
public override PaddingMode Padding
{
get
{
return this.m_Managed.Padding;
}
set
{
this.m_Managed.Padding = value;
}
}
}
}

+ 120
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/RC4UnmanagedTransform.cs View File

@ -0,0 +1,120 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using com.hitrust.b2b.Security;
using System;
using System.Security.Cryptography;
internal class RC4UnmanagedTransform : ICryptoTransform, IDisposable
{
private SymmetricKey m_Key;
public RC4UnmanagedTransform(byte[] key)
{
this.m_Key = new SymmetricKey(CryptoProvider.RsaFull, CryptoAlgorithm.RC4, key);
}
public void Dispose()
{
if (this.m_Key != null)
{
this.m_Key.Dispose();
this.m_Key = null;
}
try
{
GC.SuppressFinalize(this);
}
catch
{
}
}
~RC4UnmanagedTransform()
{
this.Dispose();
}
public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
{
if (this.m_Key == null)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if ((inputBuffer == null) || (outputBuffer == null))
{
throw new ArgumentNullException();
}
if (((inputCount < 0) || (inputOffset < 0)) || (((outputOffset < 0) || ((inputOffset + inputCount) > inputBuffer.Length)) || ((outputBuffer.Length - outputOffset) < inputCount)))
{
throw new ArgumentOutOfRangeException();
}
byte[] destinationArray = new byte[inputCount];
int length = destinationArray.Length;
Array.Copy(inputBuffer, inputOffset, destinationArray, 0, length);
if (SspiProvider.CryptEncrypt(this.m_Key.Handle, 0, 0, 0, destinationArray, ref length, length) == 0)
{
throw new CryptographicException("Could not transform data.");
}
Array.Copy(destinationArray, 0, outputBuffer, outputOffset, length);
Array.Clear(destinationArray, 0, destinationArray.Length);
return length;
}
public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
{
if (this.m_Key == null)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (inputBuffer == null)
{
throw new ArgumentNullException();
}
if (((inputCount < 0) || (inputOffset < 0)) || ((inputOffset + inputCount) > inputBuffer.Length))
{
throw new ArgumentOutOfRangeException();
}
byte[] destinationArray = new byte[inputCount];
int length = destinationArray.Length;
Array.Copy(inputBuffer, inputOffset, destinationArray, 0, length);
if (SspiProvider.CryptEncrypt(this.m_Key.Handle, 0, 1, 0, destinationArray, ref length, length) == 0)
{
throw new CryptographicException("Could not transform data.");
}
return destinationArray;
}
public bool CanReuseTransform
{
get
{
return true;
}
}
public bool CanTransformMultipleBlocks
{
get
{
return true;
}
}
public int InputBlockSize
{
get
{
return 1;
}
}
public int OutputBlockSize
{
get
{
return 1;
}
}
}
}

+ 572
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Cryptography/SymmetricKey.cs View File

@ -0,0 +1,572 @@
namespace com.hitrust.b2b.Security.Cryptography
{
using com.hitrust.b2b.Security;
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
internal sealed class SymmetricKey : IDisposable
{
private static readonly byte[] ExponentOfOne = new byte[] {
7, 2, 0, 0, 0, 0xa4, 0, 0, 0x52, 0x53, 0x41, 50, 0, 4, 0, 0,
1, 0, 0, 0, 0x4b, 0x59, 0x4e, 0x26, 0xd0, 90, 0x33, 11, 0xbd, 0x5d, 0x44, 0x53,
0x19, 0xa3, 0x74, 0x8a, 0x1c, 0x90, 0x71, 0x75, 8, 0x41, 0x19, 0xf4, 0xbc, 0x92, 0x23, 4,
0x26, 0x67, 0x8d, 190, 0xe4, 0x6f, 0x74, 0x71, 0x47, 0x60, 0x60, 0x55, 0x1f, 0x72, 0x20, 0x79,
0xf2, 0x21, 0xab, 0x91, 0xc4, 0xc9, 0x5c, 180, 0x89, 0x67, 0x52, 0x10, 0x9c, 0x71, 0x52, 0x7b,
0xd4, 0x42, 0xae, 14, 0x93, 0xa6, 0xaf, 0x8d, 0x3a, 0x61, 0x70, 0x41, 0x98, 0xc3, 0x58, 220,
0xcf, 0x4c, 0xef, 0x3e, 0xc6, 0xf3, 0xe0, 180, 0xcd, 0xfb, 0xec, 0x81, 11, 0x7a, 0x75, 0x29,
0x7a, 190, 0x40, 0xf6, 0x4a, 0x3f, 0x40, 0xb7, 0x43, 240, 0x45, 0x3f, 150, 0xf1, 0x73, 0x2f,
0x71, 0xee, 0xa7, 0x70, 0x4d, 0xf9, 0x63, 0xb8, 0x52, 0x4c, 0xf1, 0x18, 0xf3, 60, 0x21, 0x13,
0x6a, 0x9a, 0x85, 0xb7, 0xa1, 0xfd, 0xb6, 0xa4, 0xf1, 0xeb, 3, 0xd6, 0x86, 5, 0x6a, 0x63,
0x93, 0xb2, 0xe7, 0xf9, 0x2a, 0x77, 9, 0xe4, 12, 0x90, 0x2d, 0x6a, 0xa2, 0xcd, 0x37, 11,
0xc0, 0xb6, 0x1c, 150, 0xc3, 0xa7, 0x57, 0xb1, 0x77, 0xf9, 0x55, 0x11, 0x8f, 0x44, 0x8d, 0x77,
0x31, 0xa7, 0x45, 0xe0, 0x8e, 0x42, 13, 0xe4, 7, 0x53, 0xf3, 0x5c, 0x8b, 0xc7, 0xd7, 0xb8,
100, 0x1f, 0xc0, 0xea, 0x6b, 0xf7, 0x9c, 0x91, 0x19, 0xad, 0x79, 0xe9, 0xde, 0xc3, 0x45, 0x66,
0xed, 0x3e, 30, 0x90, 0x40, 0x26, 0x8b, 1, 0x7f, 0xce, 5, 0xda, 0x97, 0x8b, 0xf8, 0x47,
0x3f, 0x4f, 0x74, 0xf2, 0x6d, 0x1f, 0x16, 0xd3, 0x25, 0x57, 0x2d, 0x30, 0x6f, 60, 0xe2, 0x41,
0x86, 0xc1, 0xc7, 0x33, 1, 0x54, 3, 5, 0xa4, 0x58, 0xcc, 0x88, 0x9c, 0x8d, 0x65, 0x5e,
2, 0x5c, 0x22, 200, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0xba, 0xf6, 0x8f, 0x2a, 0x9a, 0x4c, 0x3d, 210, 0xba, 0xd8, 0x77, 0x59,
0x41, 0x8a, 0xed, 0x3d, 130, 0x24, 6, 0xc1, 0x37, 0x79, 0x81, 5, 0xfb, 0x9c, 0x6c, 0x15,
190, 0x44, 0x5c, 0xb5, 0x16, 4, 0xc4, 0x4e, 0x9d, 0x89, 0xef, 0xf1, 0x15, 0x26, 0x19, 0x16,
0x3e, 0xdd, 0xac, 0x4f, 0xe1, 170, 0x44, 0x7b, 160, 0xc5, 0xe9, 0x93, 0xc1, 0x34, 0x15, 0x67,
0x69, 0x2d, 0xc3, 0x83, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};
private int m_ExponentOfOne;
private int m_Handle;
private bool m_OwnsProvider;
private PaddingMode m_PaddingMode;
private int m_Provider;
private SymmetricKey(CryptoProvider provider) : this(false)
{
this.m_Provider = 0;
if (((SspiProvider.CryptAcquireContext(ref this.m_Provider, IntPtr.Zero, null, (int) provider, 8) == 0) && (Marshal.GetLastWin32Error() == -2146893809)) && (SspiProvider.CryptAcquireContext(ref this.m_Provider, IntPtr.Zero, null, (int) provider, 0) == 0))
{
throw new SecurityException("Cannot acquire crypto service provider.");
}
this.m_ExponentOfOne = this.CreateExponentOfOneKey();
this.m_PaddingMode = PaddingMode.None;
}
private SymmetricKey(bool ownsProvider)
{
this.m_OwnsProvider = ownsProvider;
}
public SymmetricKey(CryptoProvider provider, CryptoAlgorithm algorithm) : this(provider)
{
this.m_Handle = 0;
if (SspiProvider.CryptGenKey(this.m_Provider, new IntPtr((int) algorithm), 1, ref this.m_Handle) == 0)
{
throw new SecurityException("Cannot generate session key.");
}
}
public SymmetricKey(CryptoProvider provider, CryptoAlgorithm algorithm, byte[] buffer) : this(provider)
{
if (buffer == null)
{
throw new ArgumentNullException();
}
this.m_Handle = this.KeyFromBytes(this.m_Provider, algorithm, buffer);
}
internal SymmetricKey(int provider, int key, bool ownsProvider) : this(ownsProvider)
{
if ((key == 0) || (provider == 0))
{
throw new ArgumentNullException();
}
this.m_Provider = provider;
this.m_Handle = key;
this.m_PaddingMode = PaddingMode.None;
}
private int CreateDynamicExponentOfOneKey()
{
int phKey = 0;
int pdwDataLen = 0;
IntPtr zero = IntPtr.Zero;
try
{
if (SspiProvider.CryptGenKey(this.m_Provider, new IntPtr(1), 1, ref phKey) == 0)
{
throw new SecurityException("Cannot generate key pair.");
}
if (SspiProvider.CryptExportKey(phKey, 0, 7, 0, IntPtr.Zero, ref pdwDataLen) == 0)
{
throw new SecurityException("Cannot export generated key.");
}
zero = Marshal.AllocHGlobal(pdwDataLen);
if (SspiProvider.CryptExportKey(phKey, 0, 7, 0, zero, ref pdwDataLen) == 0)
{
throw new SecurityException("Cannot export generated key.");
}
SspiProvider.CryptDestroyKey(phKey);
phKey = 0;
int num3 = Marshal.ReadInt32(zero, 12);
int ofs = 0x10;
for (int i = 0; i < 4; i++)
{
if (i == 0)
{
Marshal.WriteByte(zero, ofs, 1);
}
else
{
Marshal.WriteByte(zero, ofs + i, 0);
}
}
ofs += 4;
ofs += num3 / 8;
ofs += num3 / 0x10;
ofs += num3 / 0x10;
for (int j = 0; j < (num3 / 0x10); j++)
{
if (j == 0)
{
Marshal.WriteByte(zero, ofs, 1);
}
else
{
Marshal.WriteByte(zero, ofs + j, 0);
}
}
ofs += num3 / 0x10;
for (int k = 0; k < (num3 / 0x10); k++)
{
if (k == 0)
{
Marshal.WriteByte(zero, ofs, 1);
}
else
{
Marshal.WriteByte(zero, ofs + k, 0);
}
}
ofs += num3 / 0x10;
ofs += num3 / 0x10;
for (int m = 0; m < (num3 / 8); m++)
{
if (m == 0)
{
Marshal.WriteByte(zero, ofs, 1);
}
else
{
Marshal.WriteByte(zero, ofs + m, 0);
}
}
if (SspiProvider.CryptImportKey(this.m_Provider, zero, pdwDataLen, 0, 1, ref phKey) == 0)
{
throw new SecurityException("Could not import modified key.");
}
}
catch (Exception exception)
{
if (phKey != 0)
{
SspiProvider.CryptDestroyKey(phKey);
}
throw exception;
}
finally
{
if (zero != IntPtr.Zero)
{
Marshal.FreeHGlobal(zero);
}
}
return phKey;
}
private int CreateExponentOfOneKey()
{
try
{
return this.CreateStaticExponentOfOneKey();
}
catch
{
return this.CreateDynamicExponentOfOneKey();
}
}
private int CreateStaticExponentOfOneKey()
{
int phKey = 0;
if (SspiProvider.CryptImportKey(this.m_Provider, ExponentOfOne, ExponentOfOne.Length, 0, 1, ref phKey) == 0)
{
throw new SecurityException("Could not import modified key.");
}
return phKey;
}
public void Dispose()
{
if (this.m_Handle != 0)
{
SspiProvider.CryptDestroyKey(this.m_Handle);
}
if (this.m_ExponentOfOne != 0)
{
SspiProvider.CryptDestroyKey(this.m_ExponentOfOne);
}
if (this.m_OwnsProvider && (this.m_Provider != 0))
{
SspiProvider.CryptReleaseContext(this.m_Provider, 0);
}
this.m_Handle = this.m_ExponentOfOne = this.m_Provider = 0;
try
{
GC.SuppressFinalize(this);
}
catch
{
}
}
~SymmetricKey()
{
this.Dispose();
}
private int GetPaddingMode(PaddingMode mode)
{
if (mode == PaddingMode.PKCS7)
{
return 1;
}
return 3;
}
private int KeyFromBytes(int provider, CryptoAlgorithm algorithm, byte[] key)
{
int dwFlags = 1;
int pbData = 0;
int num4 = 0;
int ofs = 0;
int phKey = 0;
int num8 = 0;
IntPtr algid = new IntPtr((int) algorithm);
IntPtr zero = IntPtr.Zero;
IntPtr ptr = IntPtr.Zero;
IntPtr ptr4 = IntPtr.Zero;
try
{
int size;
bool flag = false;
ptr4 = Marshal.AllocHGlobal((int) (0x54 + IntPtr.Size));
do
{
size = 0x54 + IntPtr.Size;
if (SspiProvider.CryptGetProvParam(provider, 0x16, ptr4, ref size, dwFlags) == 0)
{
break;
}
dwFlags = 0;
if (Marshal.ReadIntPtr(ptr4) == algid)
{
flag = true;
}
}
while (!flag);
if (!flag)
{
throw new SecurityException("CSP does not support selected algorithm.");
}
if (SspiProvider.CryptGenKey(provider, algid, 0, ref phKey) == 0)
{
throw new SecurityException("Cannot generate temporary key.");
}
size = 4;
if (SspiProvider.CryptGetKeyParam(phKey, 9, ref pbData, ref size, 0) == 0)
{
throw new SecurityException("Cannot retrieve key parameters.");
}
if ((key.Length * 8) > pbData)
{
throw new SecurityException("Key too big.");
}
size = IntPtr.Size;
if (SspiProvider.CryptGetKeyParam(this.m_ExponentOfOne, 7, ref zero, ref size, 0) == 0)
{
throw new SecurityException("Unable to get the private key's algorithm.");
}
size = 4;
if (SspiProvider.CryptGetKeyParam(this.m_ExponentOfOne, 9, ref num4, ref size, 0) == 0)
{
throw new SecurityException("Unable to get the key length.");
}
int cb = (((num4 / 8) + IntPtr.Size) + 4) + IntPtr.Size;
ptr = Marshal.AllocHGlobal(cb);
PUBLICKEYSTRUC structure = new PUBLICKEYSTRUC {
bType = 1,
bVersion = 2,
reserved = 0,
aiKeyAlg = algid
};
Marshal.StructureToPtr(structure, ptr, false);
Marshal.WriteIntPtr(ptr, ofs = Marshal.SizeOf(structure), zero);
ofs += IntPtr.Size;
for (int i = 0; i < key.Length; i++)
{
Marshal.WriteByte(ptr, ((ofs + key.Length) - i) - 1, key[i]);
}
size = cb - ((((IntPtr.Size + IntPtr.Size) + 4) + key.Length) + 3);
ofs += key.Length + 1;
if (SspiProvider.CryptGenRandom(provider, size, new IntPtr(ptr.ToInt64() + ofs)) == 0)
{
throw new SecurityException("Could not generate random data.");
}
for (int j = 0; j < size; j++)
{
if (Marshal.ReadByte(ptr, ofs) == 0)
{
Marshal.WriteByte(ptr, ofs, 1);
}
ofs++;
}
Marshal.WriteByte(ptr, cb - 2, 2);
if (SspiProvider.CryptImportKey(provider, ptr, cb, this.m_ExponentOfOne, 1, ref num8) == 0)
{
throw new SecurityException("Cannot import key [key has right size?].");
}
}
finally
{
if (ptr4 != IntPtr.Zero)
{
Marshal.FreeHGlobal(ptr4);
}
if (phKey != 0)
{
SspiProvider.CryptDestroyKey(phKey);
}
if (ptr != IntPtr.Zero)
{
Marshal.FreeHGlobal(ptr);
}
}
return num8;
}
public byte[] ToBytes()
{
byte[] buffer2;
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
IntPtr zero = IntPtr.Zero;
try
{
int pdwDataLen = 0;
if (SspiProvider.CryptExportKey(this.m_Handle, this.m_ExponentOfOne, 1, 0, IntPtr.Zero, ref pdwDataLen) == 0)
{
throw new SecurityException("Cannot export key.");
}
zero = Marshal.AllocHGlobal(pdwDataLen);
if (SspiProvider.CryptExportKey(this.m_Handle, this.m_ExponentOfOne, 1, 0, zero, ref pdwDataLen) == 0)
{
throw new SecurityException("Cannot export key.");
}
int num2 = 4;
int pbData = 0;
if (SspiProvider.CryptGetKeyParam(this.m_Handle, 9, ref pbData, ref num2, 0) == 0)
{
throw new SecurityException("Cannot retrieve key parameters.");
}
pbData /= 8;
byte[] destination = new byte[pbData];
int num4 = 4 + IntPtr.Size;
num4 += IntPtr.Size;
Marshal.Copy(new IntPtr(zero.ToInt64() + num4), destination, 0, destination.Length);
Array.Reverse(destination);
buffer2 = destination;
}
finally
{
if (zero != IntPtr.Zero)
{
Marshal.FreeHGlobal(zero);
}
}
return buffer2;
}
public override string ToString()
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
byte[] buffer = this.ToBytes();
StringBuilder builder = new StringBuilder(buffer.Length * 2);
for (int i = 0; i < buffer.Length; i++)
{
builder.Append(buffer[i].ToString("X2"));
}
return builder.ToString();
}
public int FeedbackSize
{
get
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
int pbData = 0;
int pdwDataLen = 4;
if (SspiProvider.CryptGetKeyParam(this.m_Handle, 5, ref pbData, ref pdwDataLen, 0) == 0)
{
throw new CryptographicException("Could not get the feedback size.");
}
return pbData;
}
set
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (SspiProvider.CryptSetKeyParam(this.m_Handle, 5, ref value, 0) == 0)
{
throw new CryptographicException("Unable to set the feedback size.");
}
}
}
public int Handle
{
get
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
return this.m_Handle;
}
}
public byte[] IV
{
get
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
int pdwDataLen = 0;
if (SspiProvider.CryptGetKeyParam(this.m_Handle, 1, (byte[]) null, ref pdwDataLen, 0) == 0)
{
throw new CryptographicException("Could not get the IV.");
}
byte[] pbData = new byte[pdwDataLen];
if (SspiProvider.CryptGetKeyParam(this.m_Handle, 1, pbData, ref pdwDataLen, 0) == 0)
{
throw new CryptographicException("Could not get the IV.");
}
return pbData;
}
set
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
if (value == null)
{
throw new ArgumentNullException();
}
if (SspiProvider.CryptSetKeyParam(this.m_Handle, 1, value, 0) == 0)
{
throw new CryptographicException("Unable to set the initialization vector.");
}
}
}
public CipherMode Mode
{
get
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
int pbData = 0;
int pdwDataLen = 4;
if (SspiProvider.CryptGetKeyParam(this.m_Handle, 4, ref pbData, ref pdwDataLen, 0) == 0)
{
throw new CryptographicException("Could not get the cipher mode.");
}
return (CipherMode) pbData;
}
set
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
int pbData = (int) value;
if (SspiProvider.CryptSetKeyParam(this.m_Handle, 4, ref pbData, 0) == 0)
{
throw new CryptographicException("Unable to set the cipher mode.");
}
}
}
public PaddingMode Padding
{
get
{
return this.m_PaddingMode;
}
set
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
int paddingMode = this.GetPaddingMode(value);
if (SspiProvider.CryptSetKeyParam(this.m_Handle, 3, ref paddingMode, 0) == 0)
{
throw new CryptographicException("Unable to set the padding type.");
}
this.m_PaddingMode = value;
}
}
public int Provider
{
get
{
if (this.m_Handle == 0)
{
throw new ObjectDisposedException(base.GetType().FullName);
}
return this.m_Provider;
}
}
}
}

+ 13
- 0
B2B/TrustPay/com/hitrust/b2b/Security/DataBlob.cs View File

@ -0,0 +1,13 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct DataBlob
{
public int cbData;
public IntPtr pbData;
}
}

+ 22
- 0
B2B/TrustPay/com/hitrust/b2b/Security/PROV_ENUMALGS_EX.cs View File

@ -0,0 +1,22 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct PROV_ENUMALGS_EX
{
public int aiAlgid;
public int dwDefaultLen;
public int dwMinLen;
public int dwMaxLen;
public int dwProtocols;
public int dwNameLen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=20)]
public string szName;
public int dwLongNameLen;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=40)]
public string szLongName;
}
}

+ 18
- 0
B2B/TrustPay/com/hitrust/b2b/Security/PUBLIC_KEY_BLOB.cs View File

@ -0,0 +1,18 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
internal struct PUBLIC_KEY_BLOB
{
public byte bType;
public byte bVersion;
public short reserved;
public int aiKeyAlg;
public int magic;
public int bitlen;
public int pubexp;
}
}

+ 15
- 0
B2B/TrustPay/com/hitrust/b2b/Security/RdnAttribute.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct RdnAttribute
{
public IntPtr pszObjId;
public int dwValueType;
public int cbData;
public IntPtr pbData;
}
}

+ 13
- 0
B2B/TrustPay/com/hitrust/b2b/Security/RelativeDistinguishedName.cs View File

@ -0,0 +1,13 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct RelativeDistinguishedName
{
public int cRDNAttr;
public IntPtr rgRDNAttr;
}
}

+ 269
- 0
B2B/TrustPay/com/hitrust/b2b/Security/SecurityConstants.cs View File

@ -0,0 +1,269 @@
namespace com.hitrust.b2b.Security
{
using System;
internal sealed class SecurityConstants
{
public const int ALG_CLASS_DATA_ENCRYPT = 0x6000;
public const int ALG_CLASS_HASH = 0x8000;
public const int ALG_CLASS_KEY_EXCHANGE = 0xa000;
public const int ALG_SID_3DES = 3;
public const int ALG_SID_AES = 0x11;
public const int ALG_SID_AES_128 = 14;
public const int ALG_SID_AES_192 = 15;
public const int ALG_SID_AES_256 = 0x10;
public const int ALG_SID_CYLINK_MEK = 12;
public const int ALG_SID_DES = 1;
public const int ALG_SID_DH_EPHEM = 2;
public const int ALG_SID_DH_SANDF = 1;
public const int ALG_SID_MD2 = 1;
public const int ALG_SID_MD4 = 2;
public const int ALG_SID_RC2 = 2;
public const int ALG_SID_RC4 = 1;
public const int ALG_SID_RSA_ANY = 0;
public const int ALG_SID_SSL3SHAMD5 = 8;
public const int ALG_TYPE_ANY = 0;
public const int ALG_TYPE_BLOCK = 0x600;
public const int ALG_TYPE_DH = 0xa00;
public const int ALG_TYPE_RSA = 0x400;
public const int ALG_TYPE_STREAM = 0x800;
public const int ASC_REQ_ALLOCATE_MEMORY = 0x100;
public const int ASC_REQ_CONFIDENTIALITY = 0x10;
public const int ASC_REQ_EXTENDED_ERROR = 0x8000;
public const int ASC_REQ_REPLAY_DETECT = 4;
public const int ASC_REQ_SEQUENCE_DETECT = 8;
public const int ASC_REQ_STREAM = 0x10000;
public const int AT_KEYEXCHANGE = 1;
public const int AUTHTYPE_CLIENT = 1;
public const int AUTHTYPE_SERVER = 2;
public const int CALG_3DES = 0x6603;
public const int CALG_AES = 0x6611;
public const int CALG_AES_128 = 0x660e;
public const int CALG_AES_192 = 0x660f;
public const int CALG_AES_256 = 0x6610;
public const int CALG_CYLINK_MEK = 0x660c;
public const int CALG_DES = 0x6601;
public const int CALG_DH_EPHEM = 0xaa02;
public const int CALG_DH_SF = 0xaa01;
public const int CALG_MD2 = 0x8001;
public const int CALG_MD4 = 0x8002;
public const int CALG_RC2 = 0x6602;
public const int CALG_RC4 = 0x6801;
public const int CALG_RSA_KEYX = 0xa400;
public const int CALG_SSL3_SHAMD5 = 0x8008;
public const int CERT_CHAIN_CACHE_END_CERT = 1;
public const int CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL = 4;
public const int CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE = 0x100;
public const int CERT_CHAIN_DISABLE_PASS1_QUALITY_FILTERING = 0x40;
public const int CERT_CHAIN_FIND_BY_ISSUER = 1;
public const int CERT_CHAIN_POLICY_ALLOW_TESTROOT_FLAG = 0x8000;
public const int CERT_CHAIN_POLICY_ALLOW_UNKNOWN_CA_FLAG = 0x10;
public const int CERT_CHAIN_POLICY_IGNORE_ALL_NOT_TIME_VALID_FLAGS = 7;
public const int CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS = 0xf00;
public const int CERT_CHAIN_POLICY_IGNORE_CA_REV_UNKNOWN_FLAG = 0x400;
public const int CERT_CHAIN_POLICY_IGNORE_CTL_NOT_TIME_VALID_FLAG = 2;
public const int CERT_CHAIN_POLICY_IGNORE_CTL_SIGNER_REV_UNKNOWN_FLAG = 0x200;
public const int CERT_CHAIN_POLICY_IGNORE_END_REV_UNKNOWN_FLAG = 0x100;
public const int CERT_CHAIN_POLICY_IGNORE_INVALID_BASIC_CONSTRAINTS_FLAG = 8;
public const int CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG = 0x40;
public const int CERT_CHAIN_POLICY_IGNORE_INVALID_POLICY_FLAG = 0x80;
public const int CERT_CHAIN_POLICY_IGNORE_NOT_TIME_NESTED_FLAG = 4;
public const int CERT_CHAIN_POLICY_IGNORE_NOT_TIME_VALID_FLAG = 1;
public const int CERT_CHAIN_POLICY_IGNORE_ROOT_REV_UNKNOWN_FLAG = 0x800;
public const int CERT_CHAIN_POLICY_IGNORE_WRONG_USAGE_FLAG = 0x20;
public const int CERT_CHAIN_POLICY_SSL = 4;
public const int CERT_CHAIN_POLICY_TRUST_TESTROOT_FLAG = 0x4000;
public const int CERT_CHAIN_RETURN_LOWER_QUALITY_CONTEXTS = 0x80;
public const int CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY = -2147483648;
public const int CERT_CHAIN_REVOCATION_CHECK_CHAIN = 0x20000000;
public const int CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = 0x40000000;
public const int CERT_CHAIN_REVOCATION_CHECK_END_CERT = 0x10000000;
public const int CERT_COMPARE_ANY = 0;
public const int CERT_COMPARE_ENHKEY_USAGE = 10;
public const int CERT_COMPARE_KEY_IDENTIFIER = 15;
public const int CERT_COMPARE_MD5_HASH = 4;
public const int CERT_COMPARE_NAME = 2;
public const int CERT_COMPARE_NAME_STR_A = 7;
public const int CERT_COMPARE_NAME_STR_W = 8;
public const int CERT_COMPARE_SHA1_HASH = 1;
public const int CERT_COMPARE_SHIFT = 0x10;
public const int CERT_DATA_ENCIPHERMENT_KEY_USAGE = 0x10;
public const int CERT_DIGITAL_SIGNATURE_KEY_USAGE = 0x80;
public const int CERT_E_CHAINING = -2146762486;
public const int CERT_E_CN_NO_MATCH = -2146762481;
public const int CERT_E_EXPIRED = -2146762495;
public const int CERT_E_PURPOSE = -2146762490;
public const int CERT_E_REVOCATION_FAILURE = -2146762482;
public const int CERT_E_REVOKED = -2146762484;
public const int CERT_E_ROLE = -2146762493;
public const int CERT_E_UNTRUSTEDROOT = -2146762487;
public const int CERT_E_UNTRUSTEDTESTROOT = -2146762483;
public const int CERT_E_VALIDITYPERIODNESTING = -2146762494;
public const int CERT_E_WRONG_USAGE = -2146762480;
public const int CERT_FIND_ANY = 0;
public const int CERT_FIND_CTL_USAGE = 0xa0000;
public const int CERT_FIND_ENHKEY_USAGE = 0xa0000;
public const int CERT_FIND_HASH = 0x10000;
public const int CERT_FIND_KEY_IDENTIFIER = 0xf0000;
public const int CERT_FIND_MD5_HASH = 0x40000;
public const int CERT_FIND_SHA1_HASH = 0x10000;
public const int CERT_FIND_SUBJECT_NAME = 0x20007;
public const int CERT_FIND_SUBJECT_STR_A = 0x70007;
public const int CERT_FIND_SUBJECT_STR_W = 0x80007;
public const int CERT_FRIENDLY_NAME_PROP_ID = 11;
public const int CERT_HASH_PROP_ID = 3;
public const int CERT_INFO_SUBJECT_FLAG = 7;
public const int CERT_KEY_AGREEMENT_KEY_USAGE = 8;
public const int CERT_KEY_CERT_SIGN_KEY_USAGE = 4;
public const int CERT_KEY_ENCIPHERMENT_KEY_USAGE = 0x20;
public const int CERT_KEY_IDENTIFIER_PROP_ID = 20;
public const int CERT_KEY_PROV_HANDLE_PROP_ID = 1;
public const int CERT_KEY_PROV_INFO_PROP_ID = 2;
public const int CERT_MD5_HASH_PROP_ID = 4;
public const int CERT_NAME_DISABLE_IE4_UTF8_FLAG = 0x10000;
public const int CERT_NAME_FRIENDLY_DISPLAY_TYPE = 5;
public const int CERT_NAME_ISSUER_FLAG = 1;
public const int CERT_NAME_SIMPLE_DISPLAY_TYPE = 4;
public const int CERT_NON_REPUDIATION_KEY_USAGE = 0x40;
public const int CERT_OFFLINE_CRL_SIGN_KEY_USAGE = 2;
public const int CERT_PVK_FILE_PROP_ID = 12;
public const int CERT_RDN_ENCODED_BLOB = 1;
public const int CERT_RDN_UNICODE_STRING = 12;
public const int CERT_SHA1_HASH_PROP_ID = 3;
public const int CERT_STORE_ADD_NEW = 1;
public const int CERT_STORE_PROV_COLLECTION = 11;
public const int CERT_STORE_PROV_FILENAME_A = 7;
public const int CERT_STORE_PROV_MEMORY = 2;
public const int CERT_STORE_PROV_PKCS7 = 5;
public const int CERT_STORE_PROV_SERIALIZED = 6;
public const int CERT_STORE_PROV_SYSTEM_A = 9;
public const int CERT_STORE_SAVE_AS_PKCS7 = 2;
public const int CERT_STORE_SAVE_AS_STORE = 1;
public const int CERT_STORE_SAVE_TO_MEMORY = 2;
public const int CERT_SYSTEM_STORE_CURRENT_SERVICE = 0x40000;
public const int CERT_SYSTEM_STORE_CURRENT_SERVICE_ID = 4;
public const int CERT_SYSTEM_STORE_CURRENT_USER = 0x10000;
public const int CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY = 0x70000;
public const int CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY_ID = 7;
public const int CERT_SYSTEM_STORE_CURRENT_USER_ID = 1;
public const int CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x20000;
public const int CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE = 0x90000;
public const int CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE_ID = 9;
public const int CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY = 0x80000;
public const int CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY_ID = 8;
public const int CERT_SYSTEM_STORE_LOCAL_MACHINE_ID = 2;
public const int CERT_SYSTEM_STORE_LOCATION_SHIFT = 0x10;
public const int CERT_SYSTEM_STORE_SERVICES = 0x50000;
public const int CERT_SYSTEM_STORE_SERVICES_ID = 5;
public const int CERT_SYSTEM_STORE_USERS = 0x60000;
public const int CERT_SYSTEM_STORE_USERS_ID = 6;
public const int CERT_X500_NAME_STR = 3;
public const int CMSG_CERT_PARAM = 12;
public const int CP_ACP = 0;
public const int CRYPT_ACQUIRE_COMPARE_KEY_FLAG = 4;
public const int CRYPT_ACQUIRE_SILENT_FLAG = 0x40;
public const int CRYPT_E_EXISTS = -2146885627;
public const int CRYPT_E_REVOCATION_OFFLINE = -2146885613;
public const int CRYPT_E_REVOKED = -2146885616;
public const int CRYPT_EXPORTABLE = 1;
public const int CRYPT_FIND_SILENT_KEYSET_FLAG = 0x40;
public const int CRYPT_FIRST = 1;
public const int CRYPT_MACHINE_KEYSET = 0x20;
public const int CRYPT_NEWKEYSET = 8;
public const int CRYPT_PREGEN = 0x40;
public const int CRYPT_SILENT = 0x40;
public const int CRYPT_USER_KEYSET = 0x1000;
public const int CRYPT_VERIFYCONTEXT = -268435456;
public const int CRYPTPROTECT_LOCAL_MACHINE = 4;
public const int CRYPTPROTECT_UI_FORBIDDEN = 1;
public const int CRYPTPROTECT_VERIFY_PROTECTION = 0x40;
public const int ERROR_MORE_DATA = 0xea;
public const int EXPORT_PRIVATE_KEYS = 4;
public const int HP_HASHVAL = 2;
public const int ISC_REQ_ALLOCATE_MEMORY = 0x100;
public const int ISC_REQ_CONFIDENTIALITY = 0x10;
public const int ISC_REQ_EXTENDED_ERROR = 0x4000;
public const int ISC_REQ_MANUAL_CRED_VALIDATION = 0x80000;
public const int ISC_REQ_MUTUAL_AUTH = 2;
public const int ISC_REQ_REPLAY_DETECT = 4;
public const int ISC_REQ_SEQUENCE_DETECT = 8;
public const int ISC_REQ_STREAM = 0x8000;
public const int ISC_RET_EXTENDED_ERROR = 0x4000;
public const string KEY_CONTAINER = "{48959A69-B181-4cdd-B135-7565701307C5}";
public const int KP_ALGID = 7;
public const int KP_BLOCKLEN = 8;
public const int KP_G = 12;
public const int KP_IV = 1;
public const int KP_KEYLEN = 9;
public const int KP_MODE = 4;
public const int KP_MODE_BITS = 5;
public const int KP_P = 11;
public const int KP_PADDING = 3;
public const int KP_X = 14;
public const int LMEM_FIXED = 0;
public const int LMEM_ZEROINIT = 0x40;
public const int NTE_BAD_KEYSET = -2146893802;
public const int NTE_EXISTS = -2146893809;
public const int PKCS_7_ASN_ENCODING = 0x10000;
public const int PKCS5_PADDING = 1;
public const int PLAINTEXTKEYBLOB = 8;
public const int PP_ENUMALGS_EX = 0x16;
public const int PRIVATEKEYBLOB = 7;
public const int PROV_DSS_DH = 13;
public const int PROV_RSA_AES = 0x18;
public const int PROV_RSA_FULL = 1;
public const int PUBLICKEYBLOB = 6;
public const int RANDOM_PADDING = 2;
public const int RSA_CSP_PUBLICKEYBLOB = 0x13;
public const int SCH_CRED_AUTO_CRED_VALIDATION = 0x20;
public const int SCH_CRED_MANUAL_CRED_VALIDATION = 8;
public const int SCH_CRED_NO_DEFAULT_CREDS = 0x10;
public const int SCH_CRED_NO_SERVERNAME_CHECK = 4;
public const int SCH_CRED_USE_DEFAULT_CREDS = 0x40;
public const int SCHANNEL_CRED_VERSION = 4;
public const int SCHANNEL_RENEGOTIATE = 0;
public const int SCHANNEL_SHUTDOWN = 1;
public const int SEC_E_ILLEGAL_MESSAGE = -2146893018;
public const int SEC_E_INCOMPLETE_MESSAGE = -2146893032;
public const int SEC_E_INVALID_TOKEN = -2146893048;
public const int SEC_E_NO_CREDENTIALS = -2146893042;
public const int SEC_E_OK = 0;
public const int SEC_I_CONTEXT_EXPIRED = 0x90317;
public const int SEC_I_CONTINUE_NEEDED = 0x90312;
public const int SEC_I_INCOMPLETE_CREDENTIALS = 0x90320;
public const int SEC_I_RENEGOTIATE = 0x90321;
public const int SECBUFFER_DATA = 1;
public const int SECBUFFER_EMPTY = 0;
public const int SECBUFFER_EXTRA = 5;
public const int SECBUFFER_STREAM_HEADER = 7;
public const int SECBUFFER_STREAM_TRAILER = 6;
public const int SECBUFFER_TOKEN = 2;
public const int SECBUFFER_VERSION = 0;
public const int SECPKG_ATTR_ISSUER_LIST_EX = 0x59;
public const int SECPKG_ATTR_LOCAL_CERT_CONTEXT = 0x54;
public const int SECPKG_ATTR_REMOTE_CERT_CONTEXT = 0x53;
public const int SECPKG_ATTR_STREAM_SIZES = 4;
public const int SECPKG_CRED_INBOUND = 1;
public const int SECPKG_CRED_OUTBOUND = 2;
public const int SECURITY_NATIVE_DREP = 0x10;
public const int SIMPLEBLOB = 1;
public const string szOID_COMMON_NAME = "2.5.4.3";
public const string szOID_ORGANIZATION_NAME = "2.5.4.10";
public const string szOID_RSA_unstructName = "1.2.840.113549.1.9.2";
public const int TRUST_E_BASIC_CONSTRAINTS = -2146869223;
public const int TRUST_E_CERT_SIGNATURE = -2146869244;
public const int X509_ANY_STRING = 6;
public const int X509_ASN_ENCODING = 1;
public const int X509_NAME = 7;
public const int X509_NAME_VALUE = 6;
public const int X509_UNICODE_ANY_STRING = 0x18;
public const int X509_UNICODE_NAME = 20;
public const int X509_UNICODE_NAME_VALUE = 0x18;
public const int ZERO_PADDING = 3;
private SecurityConstants()
{
}
}
}

+ 26
- 0
B2B/TrustPay/com/hitrust/b2b/Security/SecurityException.cs View File

@ -0,0 +1,26 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.Serialization;
[Serializable]
public class SecurityException : Exception
{
public SecurityException()
{
}
public SecurityException(string message) : base(message)
{
}
protected SecurityException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public SecurityException(string message, Exception inner) : base(message, inner)
{
}
}
}

+ 33
- 0
B2B/TrustPay/com/hitrust/b2b/Security/Signature.cs View File

@ -0,0 +1,33 @@
using System.Security.Cryptography;
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
using System.Security.Cryptography.X509Certificates;
namespace com.hitrust.b2b.Security
{
public class Signature
{
public int verifySignature(string aCertFile, string aMessage, string aBase64Signature)
{
X509Certificate certificate;
int num = 0;
try {
certificate = X509Certificate.CreateFromCertFile(aCertFile);
byte[] rgbSignature = new Base64().decode(aBase64Signature);
byte[] rgbHash = new SHA1Managed().ComputeHash(Encoding.GetEncoding("UTF-8").GetBytes(aMessage));
//certificate.PublicKey.ExportParameters(false);
RSACryptoServiceProvider publicKey = new RSACryptoServiceProvider();
publicKey.ImportParameters(new RSAParameters() { Exponent = certificate.GetPublicKey() });
if (!publicKey.VerifyHash(rgbHash, CryptoConfig.MapNameToOID("SHA1"), rgbSignature)) {
num = -1;
}
} catch (Exception exception) {
SupportClass.WriteStackTrace(exception, Console.Out);
num = 1;
}
return num;
}
}
}

+ 15
- 0
B2B/TrustPay/com/hitrust/b2b/Security/SslPolicyParameters.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct SslPolicyParameters
{
public int cbSize;
public int dwAuthType;
public int fdwChecks;
public IntPtr pwszServerName;
}
}

+ 172
- 0
B2B/TrustPay/com/hitrust/b2b/Security/SspiProvider.cs View File

@ -0,0 +1,172 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
internal sealed class SspiProvider
{
private SspiProvider()
{
}
[DllImport("crypt32.dll", SetLastError=true)]
internal static extern int CertAddCertificateContextToStore(IntPtr hCertStore, IntPtr pCertContext, int dwAddDisposition, IntPtr ppStoreContext);
[DllImport("crypt32.dll")]
internal static extern int CertAddStoreToCollection(IntPtr hCollectionStore, IntPtr hSiblingStore, int dwUpdateFlag, int dwPriority);
[DllImport("crypt32.dll")]
internal static extern int CertCloseStore(IntPtr hCertStore, int dwFlags);
[DllImport("crypt32.dll")]
internal static extern int CertCompareCertificate(int dwCertEncodingType, IntPtr pCertId1, IntPtr pCertId2);
[DllImport("crypt32.dll")]
internal static extern IntPtr CertCreateCertificateContext(int dwCertEncodingType, IntPtr pbCertEncoded, int cbCertEncoded);
[DllImport("crypt32.dll")]
internal static extern IntPtr CertCreateCRLContext(int dwCertEncodingType, byte[] pbCrlEncoded, int cbCrlEncoded);
[DllImport("crypt32.dll")]
internal static extern int CertDeleteCertificateFromStore(IntPtr pCertContext);
[DllImport("crypt32.dll")]
internal static extern IntPtr CertDuplicateCertificateContext(IntPtr pCertContext);
[DllImport("crypt32.dll")]
internal static extern IntPtr CertDuplicateStore(IntPtr hCertStore);
[DllImport("crypt32.dll")]
internal static extern int CertFindCertificateInCRL(IntPtr pCert, IntPtr pCrlContext, int dwFlags, IntPtr pvReserved, ref IntPtr ppCrlEntry);
[DllImport("crypt32.dll")]
internal static extern IntPtr CertFindCertificateInStore(IntPtr hCertStore, int dwCertEncodingType, int dwFindFlags, int dwFindType, IntPtr pvFindPara, IntPtr pPrevCertContext);
[DllImport("crypt32.dll", EntryPoint="CertFindCertificateInStore")]
internal static extern IntPtr CertFindDataBlobCertificateInStore(IntPtr hCertStore, int dwCertEncodingType, int dwFindFlags, int dwFindType, ref DataBlob pvFindPara, IntPtr pPrevCertContext);
[DllImport("crypt32.dll", CharSet=CharSet.Ansi)]
internal static extern IntPtr CertFindExtension([MarshalAs(UnmanagedType.LPStr)] string pszObjId, int cExtensions, IntPtr rgExtensions);
[DllImport("crypt32.dll", CharSet=CharSet.Ansi)]
internal static extern IntPtr CertFindRDNAttr(string pszObjId, IntPtr pName);
[DllImport("crypt32.dll", EntryPoint="CertFindCertificateInStore")]
internal static extern IntPtr CertFindStringCertificateInStore(IntPtr hCertStore, int dwCertEncodingType, int dwFindFlags, int dwFindType, [MarshalAs(UnmanagedType.LPWStr)] string pvFindPara, IntPtr pPrevCertContext);
[DllImport("crypt32.dll", EntryPoint="CertFindCertificateInStore")]
internal static extern IntPtr CertFindUsageCertificateInStore(IntPtr hCertStore, int dwCertEncodingType, int dwFindFlags, int dwFindType, ref TrustListUsage pvFindPara, IntPtr pPrevCertContext);
[DllImport("crypt32.dll")]
internal static extern void CertFreeCertificateChain(IntPtr pChainContext);
[DllImport("crypt32.dll")]
internal static extern int CertFreeCertificateContext(IntPtr pCertContext);
[DllImport("crypt32.dll")]
internal static extern int CertFreeCRLContext(IntPtr pCrlContext);
[DllImport("crypt32.dll")]
internal static extern int CertGetCertificateChain(IntPtr hChainEngine, IntPtr pCertContext, IntPtr pTime, IntPtr hAdditionalStore, ref ChainParameters pChainPara, int dwFlags, IntPtr pvReserved, ref IntPtr ppChainContext);
[DllImport("crypt32.dll")]
internal static extern int CertGetCertificateContextProperty(IntPtr pCertContext, int dwPropId, IntPtr pvData, ref int pcbData);
[DllImport("crypt32.dll")]
internal static extern int CertGetCertificateContextProperty(IntPtr pCertContext, int dwPropId, byte[] pvData, ref int pcbData);
[DllImport("crypt32.dll")]
internal static extern int CertGetEnhancedKeyUsage(IntPtr pCertContext, int dwFlags, IntPtr pUsage, ref int pcbUsage);
[DllImport("crypt32.dll")]
internal static extern int CertGetIntendedKeyUsage(int dwCertEncodingType, IntPtr pCertInfo, IntPtr pbKeyUsage, int cbKeyUsage);
[DllImport("crypt32.dll")]
internal static extern IntPtr CertGetIssuerCertificateFromStore(IntPtr hCertStore, IntPtr pSubjectContext, IntPtr pPrevIssuerContext, ref int pdwFlags);
[DllImport("crypt32.dll", EntryPoint="CertGetNameStringA")]
internal static extern int CertGetNameString(IntPtr pCertContext, int dwType, int dwFlags, IntPtr pvTypePara, IntPtr pszNameString, int cchNameString);
[DllImport("crypt32.dll")]
internal static extern int CertGetPublicKeyLength(int dwCertEncodingType, IntPtr pPublicKey);
[DllImport("crypt32.dll")]
internal static extern int CertGetValidUsages(int cCerts, IntPtr rghCerts, ref int cNumOIDs, IntPtr rghOIDs, ref int pcbOIDs);
[DllImport("crypt32.dll", CharSet=CharSet.Ansi)]
internal static extern IntPtr CertOpenStore(IntPtr lpszStoreProvider, int dwMsgAndCertEncodingType, IntPtr hCryptProv, int dwFlags, string pvPara);
[DllImport("crypt32.dll", EntryPoint="CertOpenStore")]
internal static extern IntPtr CertOpenStoreData(IntPtr lpszStoreProvider, int dwMsgAndCertEncodingType, IntPtr hCryptProv, int dwFlags, ref DataBlob pvPara);
[DllImport("crypt32.dll")]
internal static extern void CertRemoveStoreFromCollection(IntPtr hCollectionStore, IntPtr hSiblingStore);
[DllImport("crypt32.dll")]
internal static extern int CertSaveStore(IntPtr hCertStore, int dwMsgAndCertEncodingType, int dwSaveAs, int dwSaveTo, ref DataBlob pvSaveToPara, int dwFlags);
[DllImport("crypt32.dll")]
internal static extern int CertSetCertificateContextProperty(IntPtr pCertContext, int dwPropId, int dwFlags, ref CRYPT_KEY_PROV_INFO pvData);
[DllImport("crypt32.dll", EntryPoint="CertStrToNameW", CharSet=CharSet.Unicode)]
internal static extern int CertStrToName(int dwCertEncodingType, string pszX500, int dwStrType, IntPtr pvReserved, IntPtr pbEncoded, ref int pcbEncoded, IntPtr ppszError);
[DllImport("crypt32.dll")]
internal static extern int CertVerifyCertificateChainPolicy(IntPtr pszPolicyOID, IntPtr pChainContext, ref ChainPolicyParameters pPolicyPara, ref ChainPolicyStatus pPolicyStatus);
[DllImport("crypt32.dll")]
internal static extern int CertVerifyCRLRevocation(int dwCertEncodingType, IntPtr pCertId, int cCrlInfo, ref IntPtr rgpCrlInfo);
[DllImport("crypt32.dll")]
internal static extern int CertVerifyTimeValidity(IntPtr pTimeToVerify, IntPtr pCertInfo);
[DllImport("crypt32.dll")]
internal static extern int CryptAcquireCertificatePrivateKey(IntPtr pCert, int dwFlags, IntPtr pvReserved, ref int phCryptProv, ref int pdwKeySpec, ref int pfCallerFreeProv);
[DllImport("advapi32.dll", EntryPoint="CryptAcquireContextA", CharSet=CharSet.Ansi, SetLastError=true)]
internal static extern int CryptAcquireContext(ref int phProv, IntPtr pszContainer, string pszProvider, int dwProvType, int dwFlags);
[DllImport("advapi32.dll", EntryPoint="CryptAcquireContextA", CharSet=CharSet.Ansi, SetLastError=true)]
internal static extern int CryptAcquireContext(ref int phProv, string pszContainer, string pszProvider, int dwProvType, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptCreateHash(int hProv, int Algid, int hKey, int dwFlags, out int phHash);
[DllImport("crypt32.dll")]
internal static extern int CryptDecodeObject(int dwCertEncodingType, IntPtr lpszStructType, byte[] pbEncoded, int cbEncoded, int dwFlags, IntPtr pvStructInfo, ref int pcbStructInfo);
[DllImport("crypt32.dll")]
internal static extern int CryptDecodeObject(int dwCertEncodingType, IntPtr lpszStructType, IntPtr pbEncoded, int cbEncoded, int dwFlags, IntPtr pvStructInfo, ref int pcbStructInfo);
[DllImport("advapi32.dll")]
internal static extern int CryptDecrypt(int hKey, int hHash, int Final, int dwFlags, byte[] pbData, ref int pdwDataLen);
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern int CryptDecrypt(IntPtr hKey, int hHash, int Final, int dwFlags, byte[] pbData, ref int pdwDataLen);
[DllImport("advapi32.dll")]
internal static extern int CryptDestroyHash(int hHash);
[DllImport("advapi32.dll")]
internal static extern int CryptDestroyKey(int hKey);
[DllImport("advapi32.dll")]
internal static extern int CryptEncrypt(int hKey, int hHash, int Final, int dwFlags, IntPtr pbData, ref int pdwDataLen, int dwBufLen);
[DllImport("advapi32.dll")]
internal static extern int CryptEncrypt(int hKey, int hHash, int Final, int dwFlags, byte[] pbData, ref int pdwDataLen, int dwBufLen);
[DllImport("advapi32.dll")]
internal static extern int CryptEncrypt(IntPtr hKey, int hHash, int Final, int dwFlags, byte[] pbData, ref int pdwDataLen, int dwBufLen);
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern int CryptExportKey(int hKey, int hExpKey, int dwBlobType, int dwFlags, IntPtr pbData, ref int pdwDataLen);
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern int CryptExportKey(int hKey, int hExpKey, int dwBlobType, int dwFlags, byte[] pbData, ref int pdwDataLen);
[DllImport("crypt32.dll")]
internal static extern int CryptFindCertificateKeyProvInfo(IntPtr pCert, int dwFlags, IntPtr pvReserved);
[DllImport("advapi32.dll")]
internal static extern int CryptGenKey(int hProv, IntPtr Algid, int dwFlags, ref int phKey);
[DllImport("advapi32.dll")]
internal static extern int CryptGenRandom(int hProv, int dwLen, IntPtr pbBuffer);
[DllImport("advapi32.dll")]
internal static extern int CryptGetHashParam(int hHash, int dwParam, byte[] pbData, ref int pdwDataLen, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptGetKeyParam(int hKey, int dwParam, ref int pbData, ref int pdwDataLen, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptGetKeyParam(int hKey, int dwParam, ref IntPtr pbData, ref int pdwDataLen, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptGetKeyParam(int hKey, int dwParam, byte[] pbData, ref int pdwDataLen, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptGetProvParam(int hProv, int dwParam, IntPtr pbData, ref int pdwDataLen, int dwFlags);
[DllImport("advapi32.dll", CharSet=CharSet.Ansi)]
internal static extern int CryptGetUserKey(int hProv, int dwKeySpec, ref int phUserKey);
[DllImport("advapi32.dll")]
internal static extern int CryptHashData(int hHash, byte[] pbData, int dwDataLen, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptImportKey(int hProv, IntPtr pbData, int dwDataLen, int hPubKey, int dwFlags, ref int phKey);
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern int CryptImportKey(int hProv, byte[] pbData, int dwDataLen, int hPubKey, int dwFlags, ref int phKey);
[DllImport("crypt32.dll")]
internal static extern int CryptImportPublicKeyInfo(int hCryptProv, int dwCertEncodingType, ref CERT_PUBLIC_KEY_INFO pInfo, out int phKey);
[DllImport("crypt32.dll")]
internal static extern int CryptImportPublicKeyInfoEx(int hCryptProv, int dwCertEncodingType, ref CERT_PUBLIC_KEY_INFO pInfo, int aiKeyAlg, int dwFlags, IntPtr pvAuxInfo, ref int phKey);
[DllImport("crypt32.dll", CharSet=CharSet.Unicode)]
internal static extern int CryptProtectData(ref DataBlob pDataIn, string szDataDescr, ref DataBlob pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, int dwFlags, ref DataBlob pDataOut);
[DllImport("advapi32.dll")]
internal static extern int CryptReleaseContext(int hProv, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptSetHashParam(int hHash, int dwParam, byte[] pbData, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptSetKeyParam(int hKey, int dwParam, byte[] pbData, int dwFlags);
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern int CryptSetKeyParam(int hKey, int dwParam, ref DataBlob pbData, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptSetKeyParam(int hKey, int dwParam, ref int pbData, int dwFlags);
[DllImport("advapi32.dll")]
internal static extern int CryptSignHash(int hHash, int dwKeySpec, IntPtr sDescription, int dwFlags, byte[] pbSignature, ref int pdwSigLen);
[DllImport("crypt32.dll", CharSet=CharSet.Unicode)]
internal static extern int CryptUnprotectData(ref DataBlob pDataIn, IntPtr ppszDataDescr, ref DataBlob pOptionalEntropy, IntPtr pvReserved, IntPtr pPromptStruct, int dwFlags, ref DataBlob pDataOut);
[DllImport("advapi32.dll", EntryPoint="CryptVerifySignatureA", CharSet=CharSet.Ansi)]
internal static extern int CryptVerifySignature(int hHash, byte[] pbSignature, int dwSigLen, int hPubKey, IntPtr sDescription, int dwFlags);
[DllImport("crypt32.dll", CharSet=CharSet.Unicode)]
internal static extern int PFXExportCertStoreEx(IntPtr hStore, ref DataBlob pPFX, string szPassword, IntPtr pvReserved, int dwFlags);
[DllImport("crypt32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
internal static extern IntPtr PFXImportCertStore(ref DataBlob pPFX, string szPassword, int dwFlags);
[DllImport("crypt32.dll")]
internal static extern int PFXIsPFXBlob(ref DataBlob pPFX);
[DllImport("crypt32.dll", CharSet=CharSet.Unicode)]
internal static extern int PFXVerifyPassword(ref DataBlob pPFX, string szPassword, int dwFlags);
}
}

+ 13
- 0
B2B/TrustPay/com/hitrust/b2b/Security/TrustListUsage.cs View File

@ -0,0 +1,13 @@
namespace com.hitrust.b2b.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct TrustListUsage
{
public int cUsageIdentifier;
public IntPtr rgpszUsageIdentifier;
}
}

+ 205
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/Base64.cs View File

@ -0,0 +1,205 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
using System.Text;
public class Base64
{
private const int EIGHT_BIT_MASK = 0xff;
private const int LOWER_CASE_A_VALUE = 0x1a;
private int mIndex = 0;
private string mString;
private const int PLUS_VALUE = 0x3e;
private const int SIX_BIT_MASK = 0x3f;
private const int SLASH_VALUE = 0x3f;
private const int ZERO_VALUE = 0x34;
private int convertUnsignedByteToInt(byte b)
{
if (b >= 0)
{
return b;
}
return (0x100 + b);
}
public byte[] decode(string data)
{
this.mString = data;
this.mIndex = 0;
int num = 0;
int length = this.mString.Length;
for (int i = 0; i < length; i++)
{
if (this.isUsefulChar(this.mString[i]))
{
num++;
}
}
int num4 = (num * 3) / 4;
byte[] buffer = new byte[num4];
int num5 = 0;
int index = 0;
while ((index + 2) < num4)
{
num5 = this.mapCharToInt(this.NextUsefulChar) << 6;
num5 |= this.mapCharToInt(this.NextUsefulChar);
num5 = num5 << 6;
num5 |= this.mapCharToInt(this.NextUsefulChar);
num5 = num5 << 6;
num5 |= this.mapCharToInt(this.NextUsefulChar);
buffer[index + 2] = (byte) (num5 & 0xff);
num5 = num5 >> 8;
buffer[index + 1] = (byte) (num5 & 0xff);
num5 = num5 >> 8;
buffer[index] = (byte) (num5 & 0xff);
index += 3;
}
if (index == (num4 - 1))
{
num5 = this.mapCharToInt(this.NextUsefulChar) << 6;
num5 |= this.mapCharToInt(this.NextUsefulChar);
num5 = num5 >> 4;
buffer[index] = (byte) (num5 & 0xff);
}
if (index == (num4 - 2))
{
num5 = this.mapCharToInt(this.NextUsefulChar) << 6;
num5 |= this.mapCharToInt(this.NextUsefulChar);
num5 = num5 << 6;
num5 |= this.mapCharToInt(this.NextUsefulChar);
num5 = num5 >> 2;
buffer[index + 1] = (byte) (num5 & 0xff);
num5 = num5 >> 8;
buffer[index] = (byte) (num5 & 0xff);
}
return buffer;
}
public string encode(byte[] data)
{
int num = ((data.Length * 4) / 3) + 4;
StringBuilder builder = new StringBuilder((num * 0x4d) / 0x4c);
int length = data.Length;
int num3 = 0;
int num4 = 0;
while (num3 < (length - 2))
{
num4 = this.convertUnsignedByteToInt(data[num3++]) << 8;
num4 |= this.convertUnsignedByteToInt(data[num3++]);
num4 = num4 << 8;
num4 |= this.convertUnsignedByteToInt(data[num3++]);
byte b = (byte) (0x3f & num4);
num4 = num4 >> 6;
byte num6 = (byte) (0x3f & num4);
num4 = num4 >> 6;
byte num7 = (byte) (0x3f & num4);
num4 = num4 >> 6;
byte num8 = (byte) (0x3f & num4);
builder.Append(this.mapByteToChar(num8));
builder.Append(this.mapByteToChar(num7));
builder.Append(this.mapByteToChar(num6));
builder.Append(this.mapByteToChar(b));
}
if (num3 == (length - 1))
{
num4 = this.convertUnsignedByteToInt(data[num3++]) << 4;
byte num9 = (byte) (0x3f & num4);
num4 = num4 >> 6;
byte num10 = (byte) (0x3f & num4);
builder.Append(this.mapByteToChar(num10));
builder.Append(this.mapByteToChar(num9));
builder.Append("==");
}
if (num3 == (length - 2))
{
num4 = this.convertUnsignedByteToInt(data[num3++]) << 8;
num4 |= this.convertUnsignedByteToInt(data[num3++]);
num4 = num4 << 2;
byte num11 = (byte) (0x3f & num4);
num4 = num4 >> 6;
byte num12 = (byte) (0x3f & num4);
num4 = num4 >> 6;
byte num13 = (byte) (0x3f & num4);
builder.Append(this.mapByteToChar(num13));
builder.Append(this.mapByteToChar(num12));
builder.Append(this.mapByteToChar(num11));
builder.Append("=");
}
return builder.ToString();
}
private bool isUsefulChar(char c)
{
if ((((c < 'A') || (c > 'Z')) && ((c < 'a') || (c > 'z'))) && (((c < '0') || (c > '9')) && (c != '+')))
{
return (c == '/');
}
return true;
}
private char mapByteToChar(byte b)
{
if (b < 0x1a)
{
return (char) (0x41 + b);
}
if (b < 0x34)
{
return (char) (0x61 + (b - 0x1a));
}
if (b < 0x3e)
{
return (char) (0x30 + (b - 0x34));
}
if (b == 0x3e)
{
return '+';
}
if (b != 0x3f)
{
throw new ArgumentException("Byte " + b + " is not a valid Base64 value");
}
return '/';
}
private int mapCharToInt(char c)
{
if ((c >= 'A') && (c <= 'Z'))
{
return (c - 'A');
}
if ((c >= 'a') && (c <= 'z'))
{
return ((c - 'a') + 0x1a);
}
if ((c >= '0') && (c <= '9'))
{
return ((c - '0') + 0x34);
}
if (c == '+')
{
return 0x3e;
}
if (c != '/')
{
throw new ArgumentException(c + " is not a valid Base64 character.");
}
return 0x3f;
}
private char NextUsefulChar
{
get
{
char c = '_';
while (!this.isUsefulChar(c))
{
c = this.mString[this.mIndex++];
}
return c;
}
}
}
}

+ 143
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/DataVerifier.cs View File

@ -0,0 +1,143 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
public class DataVerifier
{
public static string Double2String(double aValue)
{
double num = aValue;
return num.ToString("#############.#####");
}
public static bool isValidAmount(double aAmount, int aExp)
{
bool flag = false;
string str = aAmount.ToString("#############.#####");
if (aExp >= 0)
{
if (str.IndexOf('.') == -1)
{
flag = true;
}
if (str.IndexOf('.') >= ((str.Length - aExp) - 1))
{
flag = true;
}
}
return flag;
}
public static bool isValidAmount(float aAmount, int aExp)
{
bool flag = false;
if (aExp >= 0)
{
string str = aAmount.ToString();
int index = str.IndexOf('.');
if (index == -1)
{
return true;
}
if (index >= ((str.Length - aExp) - 1))
{
flag = true;
}
}
return flag;
}
public static bool isValidDate(string aString)
{
bool flag = false;
if (aString.Length != 10)
{
return false;
}
if ((aString[4] != '/') || (aString[7] != '/'))
{
return false;
}
try
{
int.Parse(aString.Substring(0, 4));
int num = int.Parse(aString.Substring(5, 2));
int num2 = int.Parse(aString.Substring(8, 2));
if ((num < 1) || (num > 12))
{
return false;
}
if ((num2 < 1) || (num2 > 0x1f))
{
return false;
}
flag = true;
}
catch (Exception exception)
{
Console.Out.WriteLine(exception);
}
return flag;
}
public static bool isValidTime(string aString)
{
bool flag = false;
if (aString.Length != 8)
{
return false;
}
if ((aString[2] != ':') || (aString[5] != ':'))
{
return false;
}
try
{
int num = int.Parse(aString.Substring(0, 2));
int num2 = int.Parse(aString.Substring(3, 2));
int num3 = int.Parse(aString.Substring(6, 2));
if ((num < 0) || (num > 0x17))
{
return false;
}
if ((num2 < 0) || (num2 > 0x3b))
{
return false;
}
if ((num3 < 0) || (num3 > 0x3b))
{
return false;
}
flag = true;
}
catch (Exception)
{
}
return flag;
}
public static bool isValidURL(string aString)
{
if (aString.Length < 20)
{
return false;
}
if ((aString.IndexOf("http://") != 0) && (aString.IndexOf("https://") != 0))
{
return false;
}
return true;
}
[STAThread]
public static void Main(string[] argc)
{
for (int i = 0; i <= 200; i++)
{
string s = "100." + i;
Console.Out.WriteLine(string.Concat(new object[] { "Amount = [", s, "]\tResult = [", isValidAmount(float.Parse(s), 2), "]" }));
}
}
}
}

+ 176
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/HiCalendar.cs View File

@ -0,0 +1,176 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
using System.Globalization;
public class HiCalendar : GregorianCalendar
{
public static readonly int DATE = 2;
public static readonly int HOUR = 3;
public static readonly int MINUTE = 4;
public static readonly int MONTH = 1;
public static readonly int SECOND = 5;
protected internal static string[] sLocalMonthName = new string[] {"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"};
protected internal static string[] sLocalShortMonthName = new string[] {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
protected internal static string[] sLocalShortWeekName = new string[] {"日", "一", "二", "三", "四", "五", "六"};
protected internal static string[] sLocalWeekName = new string[] {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
protected internal static string[] sMonthName = new string[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
protected internal static string[] sShortMonthName = new string[] {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
protected internal static string[] sShortWeekName = new string[] {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"};
protected internal static string[] sWeekName = new string[] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
public static readonly int YEAR = 0;
public int hashCode()
{
return base.GetHashCode();
}
public virtual string toString(string aTimeFormat)
{
int length = aTimeFormat.Length;
int num2 = 0;
string str = "";
string str2 = "";
for (int i = 0; i < length; i++) {
if ((aTimeFormat[i] != '%') || (i == (length - 1))) {
goto Label_03BF;
}
i++;
char ch = aTimeFormat[i];
switch (ch) {
case 'H': {
num2 = SupportClass.CalendarManager.manager.Get(this, 8);
if (num2 < 10) {
str2 = str2 + "0";
}
str2 = str2 + num2.ToString();
continue;
}
case 'I': {
num2 = SupportClass.CalendarManager.manager.Get(this, 3);
if (num2 < 10) {
str2 = str2 + "0";
}
str2 = str2 + num2.ToString();
continue;
}
case 'L':
if (i == (length - 1)) {
continue;
}
i++;
ch = aTimeFormat[i];
if (ch > 'Y') {
break;
}
switch (ch) {
case 'B':
goto Label_021E;
case 'Y':
goto Label_0262;
}
goto Label_028D;
case 'M': {
num2 = SupportClass.CalendarManager.manager.Get(this, 4);
if (num2 < 10) {
str2 = str2 + "0";
}
str2 = str2 + num2.ToString();
continue;
}
case 'S': {
num2 = SupportClass.CalendarManager.manager.Get(this, 5);
if (num2 < 10) {
str2 = str2 + "0";
}
str2 = str2 + num2.ToString();
continue;
}
case 'B': {
str2 = str2 + sMonthName[SupportClass.CalendarManager.manager.Get(this, 1)];
continue;
}
case 'x': {
str2 = str2 + this.toString("%m/%d/%y");
continue;
}
case 'y': {
str = SupportClass.CalendarManager.manager.Get(this, 0).ToString();
str2 = str2 + str.Substring(2, 2);
continue;
}
case 'm': {
num2 = SupportClass.CalendarManager.manager.Get(this, 1) + 1;
if (num2 < 10) {
str2 = str2 + "0";
}
str2 = str2 + num2.ToString();
continue;
}
case 'X': {
str2 = str2 + this.toString("%H:%M:%S");
continue;
}
case 'Y': {
num2 = SupportClass.CalendarManager.manager.Get(this, 0);
str2 = str2 + num2.ToString();
continue;
}
case 'b': {
str2 = str2 + sShortMonthName[SupportClass.CalendarManager.manager.Get(this, 1)];
continue;
}
case 'c': {
str2 = str2 + this.toString("%x %X");
continue;
}
case 'd': {
num2 = SupportClass.CalendarManager.manager.Get(this, 7);
if (num2 < 10) {
str2 = str2 + "0";
}
str2 = str2 + num2.ToString();
continue;
}
default:
goto Label_03A9;
}
if (ch != 'b') {
if (ch == 'y') {
goto Label_023C;
}
goto Label_028D;
}
str2 = str2 + sLocalShortMonthName[SupportClass.CalendarManager.manager.Get(this, 1)];
continue;
Label_021E:
str2 = str2 + sLocalMonthName[SupportClass.CalendarManager.manager.Get(this, 1)];
continue;
Label_023C:
num2 = SupportClass.CalendarManager.manager.Get(this, 0) - 0x777;
str2 = str2 + num2.ToString();
continue;
Label_0262:
num2 = SupportClass.CalendarManager.manager.Get(this, 0) - 0x777;
str2 = str2 + num2.ToString() + "年";
continue;
Label_028D:
str2 = str2 + aTimeFormat[i];
continue;
Label_03A9:
str2 = str2 + aTimeFormat[i];
continue;
Label_03BF:
str2 = str2 + aTimeFormat[i];
}
return str2;
}
public override string ToString()
{
return base.ToString();
}
}
}

+ 114
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/IniFileParser.cs View File

@ -0,0 +1,114 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
using System.Collections;
using System.IO;
using System.Text;
public class IniFileParser
{
private string iFileName;
private SortedList iKeyValue;
public IniFileParser(string aFileName)
{
this.iFileName = aFileName;
this.initial();
}
public virtual string getTag(int aIndex)
{
return (string) this.iKeyValue.GetKey(aIndex);
}
public virtual string getValue(int aIndex)
{
return (string) this.iKeyValue.GetByIndex(aIndex);
}
public virtual string getValue(string aTag)
{
if (!this.iKeyValue.Contains(aTag))
{
return null;
}
return (string) this.iKeyValue.GetByIndex(this.iKeyValue.IndexOfKey(aTag));
}
private void initial()
{
try
{
string str;
StreamReader reader = new StreamReader(this.iFileName);
StreamReader reader2 = new StreamReader(reader.BaseStream, Encoding.UTF7);
this.iKeyValue = new SortedList();
while ((str = reader2.ReadLine()) != null)
{
if (((str.Length > 0) && (str[0] != '#')) && ((str[0] != ';') && (str[0] != ' ')))
{
this.parsingLine(str);
}
}
reader2.Close();
}
catch (IOException exception)
{
Console.Out.WriteLine(exception);
}
}
[STAThread]
public static void Main(string[] arguments)
{
if (arguments.Length == 0)
{
Console.Out.WriteLine("Usage: java ReadSource [FileName].");
}
else
{
IniFileParser parser = new IniFileParser(arguments[0]);
Console.Out.WriteLine("HiTRUST Java Utilities Class - IniFileParser Testing");
Console.Out.WriteLine("Initial File Name = [" + arguments[0] + "]");
Console.Out.WriteLine("Number of Elements = [" + parser.numberOfElements() + "]");
for (int i = 0; i < parser.numberOfElements(); i++)
{
Console.Out.WriteLine("[" + parser.getTag(i) + "] - [" + parser.getValue(i) + "]");
}
}
}
public virtual int numberOfElements()
{
return this.iKeyValue.Keys.Count;
}
private void parsingLine(string aLine)
{
int index = aLine.IndexOf("=");
int startIndex = index + 1;
int length = aLine.Length;
for (int i = startIndex; i < length; i++)
{
if (((aLine[i] == '#') || (aLine[i] == ';')) || (aLine[i] == ' '))
{
length = i;
break;
}
if (aLine[i] == '"')
{
length = aLine.LastIndexOf("\"");
startIndex++;
break;
}
}
this.iKeyValue.Add(aLine.Substring(0, index), aLine.Substring(startIndex, length - startIndex));
}
public virtual void reload()
{
this.initial();
}
}
}

+ 100
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/LogWriter.cs View File

@ -0,0 +1,100 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
using System.IO;
using System.Text;
public class LogWriter
{
internal StreamWriter iLogFile;
public LogWriter()
{
this.iLogFile = null;
}
public LogWriter(Stream aLogFile)
{
this.iLogFile = null;
this.iLogFile = new StreamWriter(aLogFile, Encoding.GetEncoding("GB2312"));
}
public virtual void closeWriter()
{
try
{
this.iLogFile.Close();
}
catch (Exception)
{
}
}
public virtual void log(string aLogString)
{
if (this.iLogFile == null)
{
Console.Out.Write(aLogString);
}
else
{
try
{
char[] chArray = aLogString.ToCharArray();
for (int i = 0; i <= chArray.Length; i++)
{
if (chArray[i] != '\r')
{
if (chArray[i] == '\n')
{
this.iLogFile.Write("\n ");
}
else
{
this.iLogFile.Write(chArray[i]);
}
}
}
}
catch (Exception)
{
}
}
}
public virtual void logNewLine(string aLogString)
{
if (this.iLogFile == null)
{
Console.Out.WriteLine(aLogString);
}
else
{
string str = new HiCalendar().toString("%Y/%m/%d-%H:%M:%S ");
try
{
this.iLogFile.Write("\n" + str);
char[] chArray = aLogString.ToCharArray();
for (int i = 0; i <= chArray.Length; i++)
{
if (chArray[i] != '\r')
{
if (chArray[i] == '\n')
{
this.iLogFile.Write("\n ");
}
else
{
this.iLogFile.Write(chArray[i]);
}
}
}
}
catch (Exception)
{
}
}
}
}
}

+ 416
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/MerchantConfig.cs View File

@ -0,0 +1,416 @@
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
namespace com.hitrust.b2b.trustpay.client
{
using Security.Certificates;
using System.Security.Cryptography.X509Certificates;
public class MerchantConfig
{
private static bool iIsInitialed = false;
private static string iKeyStoreType = "0";
private static string iLogPath = "";
private static readonly ArrayList iMerchantCertificates = new ArrayList();
private static readonly ArrayList iMerchantIDs = new ArrayList();
private static readonly ArrayList iMerchantKeys = new ArrayList();
private static int iMerchantNum = 1;
private static string iNewLine = "1";
private static IniFileParser iResourceBundle = null;
private static X509Certificate iTrustpayCertificate = null;
private static string iTrustPayConnectMethod = "http";
private static string iTrustPayServerName = "";
private static int iTrustPayServerPort = 0;
private static string iTrustPayTrxURL = "";
public const string KEY_STORE_TYPE_FILE = "0";
public const string KEY_STORE_TYPE_SIGN_SERVER = "1";
private const string RESOURCE_NAME = @"C:\WINNT\system32\B2BTrustMerchant.ini";
private const string SIGNATURE_ALGORITHM = "SHA1withRSA";
public MerchantConfig()
{
bundle();
}
private static void bindMerchantCertificateByFile()
{
string str = getParameterByName("MerchantCertFile");
if (str.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误", "商户证书储存目录档名[MerchantCertFile]配置错误!");
}
string str2 = getParameterByName("MerchantCertPassword");
if (str.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误", "商户私钥加密密码[MerchantCertPassword]配置错误!");
}
char[] separator = new char[] {','};
string[] strArray = str.Split(separator, 100);
string[] strArray2 = str2.Split(separator, 100);
if ((iMerchantNum != strArray.Length) || (iMerchantNum != strArray2.Length)) {
throw new TrxException("1007", "配置文件中MerchantID、MerchantCertFil、MerchantCertPassword属性个数不一致", "");
}
iMerchantCertificates.Clear();
iMerchantKeys.Clear();
for (int i = 0; i < iMerchantNum; i++) {
Certificate certificate = null;
if (!File.Exists(strArray[i])) {
Console.WriteLine("File does not exist: " + strArray[i]);
}
if (strArray2[i] != null) {
try {
certificate = Certificate.CreateFromPfxFile(strArray[i], strArray2[i], true, KeysetLocation.LocalMachine);
} catch (Exception exception) {
throw new TrxException("1002", "无法读取证书文档", "[" + strArray[i] + "]£?" + exception.Message);
}
}
DateTime now = DateTime.Now;
if (certificate.GetExpirationDate() < now) {
throw new TrxException("1005", "证书过期");
}
iMerchantCertificates.Add(certificate);
try {
iMerchantKeys.Add(certificate.PrivateKey);
} catch (Exception exception2) {
throw new TrxException("1003", "无法读取商户私钥", "无法生成私钥证书对象!" + exception2.Message);
}
}
}
private static void bundle()
{
if (!iIsInitialed) {
Console.Out.WriteLine("[Trustpay商户端API] 1.5 - 初始 - 开始====================");
try {
string environmentVariable = Environment.GetEnvironmentVariable("B2BTrustMerchantIniFile");
if (environmentVariable == null) {
environmentVariable = @"C:\WINNT\system32\B2BTrustMerchant.ini";
}
iResourceBundle = new IniFileParser(environmentVariable);
} catch (Exception) {
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 无法读取商户端配置文件");
throw new TrxException("1000", "无法读取商户端配置文件");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 读取系统配置文件");
iTrustPayConnectMethod = getParameterByName("TrustPayConnectMethod");
if (iTrustPayConnectMethod.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 网上支付平台通讯方式[TrustPayConnectMethod]配置错误!");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 网上支付平台通讯方式 = [" + iTrustPayConnectMethod + "]");
iTrustPayServerName = getParameterByName("TrustPayServerName");
if (iTrustPayServerName.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 网上支付平台服务器IP[TrustPayServerName]配置错误!");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 网上支付平台服务器IP = [" + iTrustPayServerName + "]");
string s = getParameterByName("TrustPayServerPort");
if (s.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 网上支付平台交易端口[TrustPayServerPort]配置错误!");
}
try {
iTrustPayServerPort = int.Parse(s);
} catch (Exception) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 网上支付平台交易端口[TrustPayServerPort]配置错误!");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 网上支付平台交易端口 = [" + s + "]");
iTrustPayTrxURL = getParameterByName("TrustPayTrxURL");
if (iTrustPayTrxURL.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 网上支付平台交易网址[TrustPayTrxURL]配置错误!");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 网上支付平台交易网址 = [" + iTrustPayTrxURL + "]");
string str3 = getParameterByName("TrustPayNewLine");
if (str3.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 网上支付平台接口特性[TrustPayNewLine]配置错误!");
}
if (str3.Equals("1")) {
iNewLine = "\n";
} else {
iNewLine = "\r\n";
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 网上支付平台接口特性 = [" + str3 + "]");
string tCertFile = getParameterByName("TrustPayCertFile");
if (tCertFile.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 网上支付平台证书[tTrustPayCertFile]配置错误!");
}
iTrustpayCertificate = getCertificate(tCertFile);
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 网上支付平台证书 = [" + tCertFile + "]");
iLogPath = getParameterByName("LogPath");
if (iLogPath.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 商户日志目录[LogPath]配置错误!");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 日志文件目录 = [" + iLogPath + "]");
string str5 = getParameterByName("MerchantID");
if (str5.Length == 0) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 商户号[MerchantID]配置错误!");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 商户编号 = [" + str5 + "]");
char[] separator = new char[] {','};
string[] strArray = str5.Split(separator, 100);
iMerchantNum = strArray.Length;
iMerchantIDs.Clear();
for (int i = 0; i < iMerchantNum; i++) {
iMerchantIDs.Add(strArray[i].Trim());
}
iKeyStoreType = getParameterByName("MerchantKeyStoreType");
if (iKeyStoreType.Equals("0")) {
bindMerchantCertificateByFile();
} else if (!iKeyStoreType.Equals("1")) {
throw new TrxException("1001", "商户端配置文件中参数设置错误 - 证书储存媒体配置错误!");
}
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 商户证书及私钥初始完成");
iIsInitialed = true;
Console.Out.WriteLine("[Trustpay商户端API] - 初始 - 完成====================");
}
}
private static XMLDocument fileSignMessage(int aMerchantNo, XMLDocument aMessage)
{
RSACryptoServiceProvider provider = MerchantKey(aMerchantNo);
byte[] rgbHash = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(aMessage.ToString()));
byte[] data = provider.SignHash(rgbHash, CryptoConfig.MapNameToOID("SHA1"));
string str = new Base64().encode(data);
return new XMLDocument("<Message>" + aMessage.ToString() + "</Message><Signature-Algorithm>SHA1withRSA</Signature-Algorithm><Signature>" + str + "</Signature>");
}
private static X509Certificate getCertificate(string tCertFile)
{
X509Certificate certificate = null;
try {
certificate = X509Certificate.CreateFromCertFile(tCertFile);
} catch (Exception) {
throw new TrxException("1002", "无法读取证书文档[" + tCertFile + "]!");
}
return certificate;
}
public static string getParameterByName(string aParamName)
{
return getParameterByName(aParamName, true);
}
public static string getParameterByName(string aParamName, bool aThrowException)
{
if (iResourceBundle == null) {
bundle();
}
string str = null;
try {
str = iResourceBundle.getValue(aParamName).Trim();
if (str.Equals("") & aThrowException) {
throw new TrxException("1001", "商户端配置文件中参数设置错误", " - 未设定[" + aParamName + "]参数值!");
}
} catch (Exception) {
if (aThrowException) {
throw new TrxException("1001", "商户端配置文件中参数设置错误", " - 无[" + aParamName + "]参数!");
}
}
return str;
}
public static BufferedStream getTrxLogFile(string aFileName)
{
bundle();
BufferedStream stream = null;
string path = "";
try {
HiCalendar calendar = new HiCalendar();
path = iLogPath + "/" + aFileName + "." + calendar.toString("%Y%m%d.log");
stream = new BufferedStream(new FileStream(path, FileMode.Append));
} catch (IOException) {
throw new TrxException("1004", "无法写入交易日志文档", " - 系统无法写入交易日志至[" + path + "]中!");
}
return stream;
}
public static Certificate MerchantCertificate(int aMerchantNo)
{
bundle();
return (Certificate)iMerchantCertificates[aMerchantNo - 1];
}
public static string MerchantID(int aMerchantNo)
{
bundle();
return (string)iMerchantIDs[aMerchantNo - 1];
}
public static RSACryptoServiceProvider MerchantKey(int aMerchantNo)
{
bundle();
return (RSACryptoServiceProvider)iMerchantKeys[aMerchantNo - 1];
}
public static XMLDocument signMessage(int aMerchantNo, XMLDocument aMessage)
{
bundle();
XMLDocument document = null;
try {
string keyStoreType = KeyStoreType;
if (keyStoreType.Equals("0")) {
return fileSignMessage(aMerchantNo, aMessage);
}
if (keyStoreType.Equals("1")) {
document = signServerSignMessage(aMessage);
}
} catch (TrxException exception) {
throw exception;
} catch (Exception exception2) {
throw new TrxException("1102", "签名交易报文时发生错误 - " + exception2.Message);
}
return document;
}
private static XMLDocument signServerSignMessage(XMLDocument aMessage)
{
string aXMLString = "";
Socket socket = null;
string hostName = getParameterByName("SignServerIP");
int port = int.Parse(getParameterByName("SignServerPort"));
string str3 = getParameterByName("SignServerPassword");
try {
IPEndPoint remoteEP = new IPEndPoint(Dns.GetHostEntry(hostName).AddressList[0], port);
socket = new Socket(remoteEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 0x2710);
socket.Connect(remoteEP);
string str4 = new Base64().encode(Encoding.UTF8.GetBytes(aMessage.ToString()));
string s = "<SignReq><Password>" + str3 + "</Password><Signature-Algorithm>SHA1withRSA</Signature-Algorithm><Data>" + str4 + "</Data></SignReq>\n";
socket.Send(Encoding.ASCII.GetBytes(s));
byte[] buffer = new byte[0x800];
int count = socket.Receive(buffer);
XMLDocument document = new XMLDocument(Encoding.ASCII.GetString(buffer, 0, count));
string str6 = "";
if (!document.getValueNoNull("RC").Equals("0")) {
throw new TrxException("1104", "签名服务器返回签名错误", "错误代码[" + document.getValueNoNull("RC") + "]");
}
str6 = document.getValueNoNull("Signature");
aXMLString = "<Message>" + aMessage.ToString() + "</Message><Signature-Algorithm>SHA1withRSA</Signature-Algorithm><Signature>" + str6 + "</Signature>";
} catch (TrxException exception) {
throw exception;
} catch (Exception exception2) {
throw new TrxException("1103", "无法连线签名服务器", exception2.StackTrace);
} finally {
if (socket != null) {
socket.Close();
}
}
return new XMLDocument(aXMLString);
}
public static XMLDocument verifySign(XMLDocument aMessage)
{
bundle();
XMLDocument document = aMessage.getValue("Message");
if (document == null) {
throw new TrxException("1301", "网上支付平台的响应报文不完整", "无[Message]段!");
}
if (aMessage.getValueNoNull("Signature-Algorithm") == null) {
throw new TrxException("1301", "网上支付平台的响应报文不完整", "无[Signature-Algorithm]段!");
}
string data = aMessage.getValueNoNull("Signature");
if (data == null) {
throw new TrxException("1301", "网上支付平台的响应报文不完整", "无[Signature]段!");
}
byte[] rgbSignature = new Base64().decode(data);
try {
SHA1Managed managed = new SHA1Managed();
byte[] rgbHash = managed.ComputeHash(Encoding.GetEncoding("UTF-8").GetBytes(document.ToString()));
RSACryptoServiceProvider provider = new RSACryptoServiceProvider(new CspParameters {
Flags = CspProviderFlags.UseMachineKeyStore
});
RSAParameters parameters = new RSAParameters() { Exponent = TrustpayCertificate.GetPublicKey() };
provider.ImportParameters(parameters);
bool flag = provider.VerifyHash(rgbHash, CryptoConfig.MapNameToOID("SHA1"), rgbSignature);
managed.Clear();
provider.Clear();
if (!flag) {
throw new TrxException("1302", "网上支付平台的响应报文签名验证失败!");
}
} catch (TrxException exception) {
throw exception;
} catch (Exception exception2) {
SupportClass.WriteStackTrace(exception2, Console.Out);
throw new TrxException("1302", "网上支付平台的响应报文签名验证失败! -- " + exception2.StackTrace);
}
return document;
}
public static string KeyStoreType
{
get
{
bundle();
return iKeyStoreType;
}
}
public static int MerchantNum
{
get
{
bundle();
return iMerchantNum;
}
}
public static X509Certificate TrustpayCertificate
{
get
{
bundle();
return iTrustpayCertificate;
}
}
public static string TrustPayConnectMethod
{
get
{
bundle();
return iTrustPayConnectMethod;
}
}
public static string TrustPayNewLine
{
get
{
bundle();
return iNewLine;
}
}
public static string TrustPayServerName
{
get
{
bundle();
return iTrustPayServerName;
}
}
public static int TrustPayServerPort
{
get
{
bundle();
return iTrustPayServerPort;
}
}
public static string TrustPayTrxURL
{
get
{
bundle();
return iTrustPayTrxURL;
}
}
public static BufferedStream TrxLogFile
{
get { return getTrxLogFile("TrxLog"); }
}
}
}

+ 15
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/MyPolicy.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class MyPolicy : ICertificatePolicy
{
public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
{
return true;
}
}
}

+ 96
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/TrxException.cs View File

@ -0,0 +1,96 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
public class TrxException : Exception
{
protected internal string iCode;
protected internal string iDetailMessage;
public const string TRX_EXC_CODE_1000 = "1000";
public const string TRX_EXC_CODE_1001 = "1001";
public const string TRX_EXC_CODE_1002 = "1002";
public const string TRX_EXC_CODE_1003 = "1003";
public const string TRX_EXC_CODE_1004 = "1004";
public const string TRX_EXC_CODE_1005 = "1005";
public const string TRX_EXC_CODE_1006 = "1006";
public const string TRX_EXC_CODE_1007 = "1007";
public const string TRX_EXC_CODE_1100 = "1100";
public const string TRX_EXC_CODE_1101 = "1101";
public const string TRX_EXC_CODE_1102 = "1102";
public const string TRX_EXC_CODE_1103 = "1103";
public const string TRX_EXC_CODE_1104 = "1104";
public const string TRX_EXC_CODE_1201 = "1201";
public const string TRX_EXC_CODE_1202 = "1202";
public const string TRX_EXC_CODE_1203 = "1203";
public const string TRX_EXC_CODE_1204 = "1204";
public const string TRX_EXC_CODE_1205 = "1205";
public const string TRX_EXC_CODE_1206 = "1206";
public const string TRX_EXC_CODE_1301 = "1301";
public const string TRX_EXC_CODE_1302 = "1302";
public const string TRX_EXC_CODE_1303 = "1303";
public const string TRX_EXC_CODE_1999 = "1999";
public const string TRX_EXC_MSG_1000 = "无法读取商户端配置文件";
public const string TRX_EXC_MSG_1001 = "商户端配置文件中参数设置错误";
public const string TRX_EXC_MSG_1002 = "无法读取证书文档";
public const string TRX_EXC_MSG_1003 = "无法读取商户私钥";
public const string TRX_EXC_MSG_1004 = "无法写入交易日志文档";
public const string TRX_EXC_MSG_1005 = "证书过期";
public const string TRX_EXC_MSG_1006 = "证书格式错误";
public const string TRX_EXC_MSG_1007 = "配置文件中MerchantID、MerchantCertFil、MerchantCertPassword属性个数不一致";
public const string TRX_EXC_MSG_1100 = "商户提交的交易资料不完整";
public const string TRX_EXC_MSG_1101 = "商户提交的交易资料不合法";
public const string TRX_EXC_MSG_1102 = "签名交易报文时发生错误";
public const string TRX_EXC_MSG_1103 = "无法连线签名服务器";
public const string TRX_EXC_MSG_1104 = "签名服务器返回签名错误";
public const string TRX_EXC_MSG_1201 = "无法连线网上支付平台";
public const string TRX_EXC_MSG_1202 = "提交交易时发生网络错误";
public const string TRX_EXC_MSG_1203 = "无法接收到网上支付平台的响应";
public const string TRX_EXC_MSG_1204 = "接收网上支付平台响应报文时发生网络错误";
public const string TRX_EXC_MSG_1205 = "无法辨识网上支付平台的响应报文";
public const string TRX_EXC_MSG_1206 = "网上支付平台服务暂时停止";
public const string TRX_EXC_MSG_1301 = "网上支付平台的响应报文不完整";
public const string TRX_EXC_MSG_1302 = "网上支付平台的响应报文签名验证失败!";
public const string TRX_EXC_MSG_1303 = "无法辨识网上支付平台的交易结果";
public const string TRX_EXC_MSG_1999 = "系统发生无法预期的错误";
public TrxException(string aCode, string aMessage) : base(aMessage)
{
this.iCode = "";
this.iDetailMessage = "";
this.iCode = aCode.Trim();
}
public TrxException(string aCode, string aMessage, string aDetailMessage) : base(aMessage.Trim())
{
this.iCode = "";
this.iDetailMessage = "";
this.iCode = aCode.Trim();
this.iDetailMessage = aDetailMessage.Trim();
}
public virtual string Code
{
get
{
return this.iCode;
}
}
public virtual string DetailMessage
{
get
{
return this.iDetailMessage;
}
}
public override string Message
{
get
{
return base.Message;
}
}
}
}

+ 157
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/TrxRequest.cs View File

@ -0,0 +1,157 @@
namespace com.hitrust.b2b.trustpay.client
{
using Security;
using System;
using System.IO;
using System.Net;
using System.Text;
public abstract class TrxRequest
{
public const string EC_MERCHANT_TYPE_B2B = "B2B";
public const string EC_MERCHANT_TYPE_B2C = "B2C";
private readonly string iECMerchantType = "";
private LogWriter iLogWriter = null;
public TrxRequest(string aECMerchantType)
{
this.iECMerchantType = aECMerchantType;
}
protected internal abstract void checkRequest();
private XMLDocument composeRequestMessage(int aMerchantNo, XMLDocument aMessage)
{
return new XMLDocument("<Merchant><ECMerchantType>" + this.iECMerchantType + "</ECMerchantType><MerchantID>" + MerchantConfig.MerchantID(aMerchantNo) + "</MerchantID></Merchant>" + aMessage.ToString());
}
protected internal abstract TrxResponse constructResponse(XMLDocument aResponseMessage);
public virtual TrxResponse extendPostRequest(int aMerchantNo)
{
TrxResponse response = null;
try {
this.iLogWriter = new LogWriter(MerchantConfig.TrxLogFile);
this.iLogWriter.logNewLine("检查交易请求是否合法:");
this.checkRequest();
this.iLogWriter.logNewLine("正确");
XMLDocument requestMessage = this.RequestMessage;
requestMessage = this.composeRequestMessage(aMerchantNo, requestMessage);
this.iLogWriter.logNewLine("签名后的交易请求报文:");
requestMessage = MerchantConfig.signMessage(aMerchantNo, requestMessage);
this.iLogWriter.logNewLine(requestMessage.ToString());
this.iLogWriter.logNewLine("发送交易报文至网上支付平台:");
XMLDocument aMessage = this.sendMessage(requestMessage);
this.iLogWriter.logNewLine("验证网上支付平台响应报文的签名:");
MerchantConfig.verifySign(aMessage);
this.iLogWriter.log("正确");
this.iLogWriter.logNewLine("生成交易响应对象:");
response = this.constructResponse(aMessage);
this.iLogWriter.logNewLine("交易结果:[" + response.ReturnCode + "]");
this.iLogWriter.logNewLine("错误信息:[" + response.ErrorMessage + "]");
} catch (TrxException exception) {
response = new TrxResponse(exception.Code, exception.Message + " - " + exception.DetailMessage);
if (this.iLogWriter != null) {
this.iLogWriter.logNewLine("错误代码:[" + response.ReturnCode + "] 错误信息:[" + response.ErrorMessage + "]");
}
} catch (Exception exception2) {
response = new TrxResponse("1999", "系统发生无法预期的错误 - " + exception2.Message);
if (this.iLogWriter != null) {
this.iLogWriter.logNewLine("错误代码:[" + response.ReturnCode + "] 错误信息:[" + response.ErrorMessage + "]");
}
}
if (this.iLogWriter != null) {
this.iLogWriter.closeWriter();
}
return response;
}
public virtual TrxResponse postRequest()
{
return this.extendPostRequest(1);
}
private XMLDocument sendMessage(XMLDocument aMessage)
{
string s = "<MSG>" + aMessage.ToString() + "</MSG>";
this.iLogWriter.logNewLine("提交网上支付平台的报文:\n" + s);
try {
int length = Encoding.UTF8.GetBytes(s).Length;
} catch (Exception exception) {
SupportClass.WriteStackTrace(exception, Console.Out);
throw new TrxException("1999", "系统发生无法预期的错误", exception.Message);
}
string aXMLString = "";
XMLDocument document;
ServicePointManager.ServerCertificateValidationCallback = delegate {
return true;
};
string str3 = MerchantConfig.TrustPayConnectMethod + "://" + MerchantConfig.TrustPayServerName;
if ((MerchantConfig.TrustPayConnectMethod.Equals("https") && (MerchantConfig.TrustPayServerPort != 0x1bb)) || (MerchantConfig.TrustPayConnectMethod.Equals("http") && (MerchantConfig.TrustPayServerPort != 80))) {
str3 = str3 + ":" + MerchantConfig.TrustPayServerPort;
}
try {
this.iLogWriter.logNewLine("连线网上支付平台:[" + str3 + "] ");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(str3 + MerchantConfig.TrustPayTrxURL);
if (MerchantConfig.getParameterByName("ProxyIP", false) != null) {
request.Proxy = new WebProxy(MerchantConfig.getParameterByName("ProxyIP", false), int.Parse(MerchantConfig.getParameterByName("ProxyPort", false)));
}
request.Headers.Add("Cookie", "JSESSIONID=aIG-RvFXRUU");
request.Method = "POST";
request.ProtocolVersion = HttpVersion.Version10;
request.ContentType = "application/x-www-form-urlencoded";
this.iLogWriter.log("成功");
this.iLogWriter.logNewLine("提交交易报文:");
byte[] bytes = Encoding.UTF8.GetBytes(s);
request.ContentLength = bytes.Length;
BufferedStream stream = new BufferedStream(request.GetRequestStream());
if (!stream.CanWrite) {
throw new TrxException("1201", "无法连线网上支付平台", "无法连线到[" + str3 + "]");
}
stream.Write(bytes, 0, bytes.Length);
stream.Flush();
stream.Close();
this.iLogWriter.log("成功");
this.iLogWriter.logNewLine("等待网上支付平台返回交易结果:");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding("UTF-8");
StreamReader reader = new StreamReader(responseStream, encoding);
for (string str4 = null; (str4 = reader.ReadLine()) != null; str4 = reader.ReadLine()) {
aXMLString = aXMLString + str4;
if (str4.IndexOf("</MSG>") != -1) {
break;
}
}
response.Close();
this.iLogWriter.log("成功");
this.iLogWriter.logNewLine("返回报文:");
this.iLogWriter.log("\n" + aXMLString.ToString());
if (response.StatusCode != HttpStatusCode.OK) {
throw new TrxException("1206", "网上支付平台服务暂时停止");
}
document = new XMLDocument(aXMLString).getValue("MSG");
if (document == null) {
throw new TrxException("1205", "无法辨识网上支付平台的响应报文", "无[MSG]段!");
}
} catch (WebException exception2) {
this.iLogWriter.logNewLine(exception2.ToString());
throw new TrxException("1201", "无法连线网上支付平台", "无法连线到[" + str3 + "], " + exception2.Message);
} catch (IOException exception3) {
this.iLogWriter.logNewLine(exception3.ToString());
throw new TrxException("1202", "提交交易时发生网络错误", "连线中断!");
} catch (SecurityException exception4) {
this.iLogWriter.logNewLine(exception4.ToString());
throw new TrxException("1201", "无法连线网上支付平台", "进程权限太低!");
} catch (TrxException exception5) {
throw exception5;
} catch (Exception exception6) {
this.iLogWriter.logNewLine(exception6.StackTrace);
throw new TrxException("1201", "无法连线网上支付平台", exception6.StackTrace);
}
return document;
}
protected internal abstract XMLDocument RequestMessage { get; }
}
}

+ 136
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/TrxResponse.cs View File

@ -0,0 +1,136 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
public class TrxResponse
{
protected internal string iErrorMessage;
protected internal XMLDocument iResponseMessage;
protected internal string iReturnCode;
protected internal string iSignature;
public const string RC_SUCCESS = "0000";
public const string STATUS_CANCEL = "5";
public const string STATUS_CHECK = "1";
public const string STATUS_FAILURE = "3";
public const string STATUS_NO_RESPONSE = "9";
public const string STATUS_ORIGINAL = "0";
public const string STATUS_REJECT = "4";
public const string STATUS_SUCCESS = "2";
protected internal TrxResponse()
{
this.iReturnCode = "";
this.iErrorMessage = "";
this.iSignature = "";
this.InitBlock();
}
public TrxResponse(XMLDocument aXMLDocument)
{
this.iReturnCode = "";
this.iErrorMessage = "";
this.iSignature = "";
this.InitBlock();
this.init(aXMLDocument);
}
public TrxResponse(string aReturnCode, string aErrorMessage)
{
this.iReturnCode = "";
this.iErrorMessage = "";
this.iSignature = "";
this.InitBlock();
this.setReturnCode(aReturnCode);
this.setErrorMessage(aErrorMessage);
}
public virtual string getValue(string aTag)
{
return this.iResponseMessage.getValueNoNull(aTag);
}
protected internal virtual void init(XMLDocument aXMLDocument)
{
this.iResponseMessage = aXMLDocument.getValue("Message");
this.iSignature = aXMLDocument.getValueNoNull("Signature");
XMLDocument document = this.iResponseMessage.getValue("ReturnCode");
if (document == null)
{
throw new TrxException("1303", "无法辨识网上支付平台的交易结果", "无法取得[ReturnCode]!");
}
this.setReturnCode(document.ToString());
XMLDocument document2 = this.iResponseMessage.getValue("ErrorMessage");
if (document2 != null)
{
this.setErrorMessage(document2.ToString());
}
}
private void InitBlock()
{
this.iResponseMessage = new XMLDocument("");
}
public virtual bool isSuccess()
{
return this.iReturnCode.Equals("0000");
}
public virtual TrxResponse setErrorMessage(string aErrorMessage)
{
this.iErrorMessage = aErrorMessage.Trim();
return this;
}
public virtual TrxResponse setReturnCode(string aReturnCode)
{
this.iReturnCode = aReturnCode.Trim();
return this;
}
public virtual string ErrorMessage
{
get
{
return this.iErrorMessage;
}
set
{
this.iErrorMessage = value.Trim();
}
}
public virtual string ResponseMessage
{
get
{
return this.iResponseMessage.ToString();
}
}
public virtual string ReturnCode
{
get
{
return this.iReturnCode;
}
set
{
this.iReturnCode = value.Trim();
}
}
public virtual string Signature
{
get
{
return this.iSignature;
}
set
{
this.iSignature = value.Trim();
}
}
}
}

+ 130
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/XMLDocument.cs View File

@ -0,0 +1,130 @@
namespace com.hitrust.b2b.trustpay.client
{
using System;
using System.Collections;
public class XMLDocument
{
private string iXMLString;
public XMLDocument()
{
this.iXMLString = "";
}
public XMLDocument(string aXMLString)
{
this.iXMLString = "";
this.init(aXMLString);
}
public virtual XMLDocument deleteFirstTagDocument()
{
string str = this.getFirstTagName();
int index = this.iXMLString.IndexOf("<" + str + ">");
int num2 = this.iXMLString.IndexOf("</" + str + ">");
if (num2 > index)
{
this.iXMLString = this.iXMLString.Substring((num2 + str.Length) + 3);
}
return this;
}
public virtual ArrayList getDocuments(string aTag)
{
string iXMLString = this.iXMLString;
ArrayList list = new ArrayList();
while (true)
{
XMLDocument document = null;
int index = iXMLString.IndexOf("<" + aTag.Trim() + ">");
int num2 = iXMLString.IndexOf("</" + aTag.Trim() + ">");
if (((index == -1) || (num2 == -1)) || (index > num2))
{
return list;
}
document = new XMLDocument(iXMLString.Substring(index, ((num2 + aTag.Length) + 3) - index));
list.Add(document);
iXMLString = iXMLString.Substring(num2 + 1);
}
}
public virtual string getFirstTagName()
{
string str = null;
int index = this.iXMLString.IndexOf('<');
int num2 = this.iXMLString.IndexOf('>');
if (num2 > index)
{
str = this.iXMLString.Substring(index + 1, num2 - (index + 1));
}
return str;
}
public virtual XMLDocument getFormatDocument(string aSpace)
{
return this.getFormatDocument(0, aSpace);
}
private XMLDocument getFormatDocument(int aLevel, string aSpace)
{
string str2;
string str = aSpace;
for (int i = 0; i < aLevel; i++)
{
str = str + aSpace;
}
if (this.getFirstTagName() == null)
{
return this;
}
string aXMLString = "\n";
for (XMLDocument document = new XMLDocument(this.iXMLString); (str2 = document.getFirstTagName()) != null; document = document.deleteFirstTagDocument())
{
XMLDocument document2 = document.getValue(str2);
string str4 = "";
if (document2.getFirstTagName() != null)
{
str4 = str;
}
aXMLString = string.Concat(new object[] { aXMLString, str, "<", str2, ">", document2.getFormatDocument(aLevel + 1, aSpace), str4, "</", str2, ">\n" });
}
return new XMLDocument(aXMLString);
}
public virtual XMLDocument getValue(string aTag)
{
XMLDocument document = null;
int index = this.iXMLString.IndexOf("<" + aTag.Trim() + ">");
int num2 = this.iXMLString.IndexOf("</" + aTag.Trim() + ">");
if (((index >= 0) && (num2 >= 0)) && (index < num2))
{
document = new XMLDocument(this.iXMLString.Substring((index + aTag.Length) + 2, num2 - ((index + aTag.Length) + 2)));
}
return document;
}
public virtual string getValueNoNull(string aTag)
{
string str = "";
XMLDocument document = this.getValue(aTag);
if (document != null)
{
str = document.ToString();
}
return str;
}
public XMLDocument init(string aXMLString)
{
this.iXMLString = aXMLString;
return this;
}
public override string ToString()
{
return this.iXMLString;
}
}
}

+ 87
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/DownloadTrnxRequest.cs View File

@ -0,0 +1,87 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class DownloadTrnxRequest : TrxRequest
{
private string iMerchantRemarks;
private string iMerchantTrnxDate;
public const int MERCHANT_REMARKS_LEN = 200;
public DownloadTrnxRequest() : base("B2B")
{
this.iMerchantTrnxDate = "";
this.iMerchantRemarks = "";
}
public DownloadTrnxRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iMerchantTrnxDate = "";
this.iMerchantRemarks = "";
this.MerchantTrnxDate = aXMLDocument.getValueNoNull("MerchantTrnxDate");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iMerchantTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易日期!");
}
if (this.iMerchantTrnxDate.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易日期不合法!");
}
if (!DataVerifier.isValidDate(this.iMerchantTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交交易日期不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxDate
{
get
{
return this.iMerchantTrnxDate;
}
set
{
this.iMerchantTrnxDate = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<TrxRequest>").Append("<TrxType>DownloadTrnx</TrxType>").Append("<MerchantTrnxDate>" + this.iMerchantTrnxDate + "</MerchantTrnxDate>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
}
}

+ 339
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/FreezeRequest.cs View File

@ -0,0 +1,339 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class FreezeRequest : TrxRequest
{
public const int ACCOUNT_BANK_URL_LEN = 50;
public const int ACCOUNT_NAME_URL_LEN = 50;
public const int ACCOUNT_NO_URL_LEN = 20;
public const int CORPOR_CUSTOMER_URL_LEN = 100;
private string iAccountBank;
private string iAccountName;
private string iAccountNo;
private string iCorporationCustomerNo;
private string iMerchantRemarks;
private string iMerchantTrnxNo;
private string iResultNotifyURL;
private double iTrnxAmount;
private string iTrnxDate;
private com.hitrust.b2b.trustpay.client.b2b.TrnxInfo iTrnxInfo;
private string iTrnxTime;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 100;
public const int RESULT_NOTIFY_URL_LEN = 200;
public FreezeRequest() : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
}
public FreezeRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
this.TrnxInfo = new com.hitrust.b2b.trustpay.client.b2b.TrnxInfo(aXMLDocument);
this.CorporationCustomerNo = aXMLDocument.getValueNoNull("CorporationCustomerNo");
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
try
{
this.TrnxAmount = double.Parse(aXMLDocument.getValueNoNull("TrnxAmount"));
}
catch (Exception)
{
}
this.TrnxDate = aXMLDocument.getValueNoNull("TrnxDate");
this.TrnxTime = aXMLDocument.getValueNoNull("TrnxTime");
this.AccountNo = aXMLDocument.getValueNoNull("AccountNo");
this.AccountName = aXMLDocument.getValueNoNull("AccountName");
this.AccountBank = aXMLDocument.getValueNoNull("AccountBank");
this.ResultNotifyURL = aXMLDocument.getValueNoNull("ResultNotifyURL");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iTrnxInfo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易详细信息!");
}
if (this.iCorporationCustomerNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定企业客户代码!");
}
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iTrnxAmount <= 0.0)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易金额!");
}
if (this.iTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易日期!");
}
if (this.iTrnxTime == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易时间!");
}
if (this.iAccountNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账号!");
}
if (this.iAccountName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账户名!");
}
if (this.iAccountBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账户开户行!");
}
if (this.iResultNotifyURL == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易结果回传网址!");
}
if (!this.iTrnxInfo.Valid)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易详细信息不合法!");
}
if (this.iCorporationCustomerNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iCorporationCustomerNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (this.iAccountNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账号不合法!");
}
if (this.iAccountName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户名不合法!");
}
if (this.iAccountBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户开户行不合法!");
}
if (!DataVerifier.isValidDate(this.iTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易日期不合法!");
}
if (!DataVerifier.isValidTime(this.iTrnxTime))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易时间不合法!");
}
if (!DataVerifier.isValidAmount(this.iTrnxAmount, 2))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易金额不合法!");
}
if (!DataVerifier.isValidURL(this.iResultNotifyURL))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (this.iResultNotifyURL.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iResultNotifyURL)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string AccountBank
{
get
{
return this.iAccountBank;
}
set
{
this.iAccountBank = value.Trim();
}
}
public virtual string AccountName
{
get
{
return this.iAccountName;
}
set
{
this.iAccountName = value.Trim();
}
}
public virtual string AccountNo
{
get
{
return this.iAccountNo;
}
set
{
this.iAccountNo = value.Trim();
}
}
public virtual string CorporationCustomerNo
{
get
{
return this.iCorporationCustomerNo;
}
set
{
this.iCorporationCustomerNo = value.Trim();
}
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<Corporation>").Append("<CorporationCustomerNo>" + this.iCorporationCustomerNo + "</CorporationCustomerNo>").Append("</Corporation>").Append("<TrxRequest>").Append("<TrxType>Freeze</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<TrnxAmount>" + DataVerifier.Double2String(this.iTrnxAmount) + "</TrnxAmount>").Append("<TrnxDate>" + this.iTrnxDate + "</TrnxDate>").Append("<TrnxTime>" + this.iTrnxTime + "</TrnxTime>").Append("<Account>").Append("<AccountNo>" + this.iAccountNo + "</AccountNo>").Append("<AccountName>" + this.iAccountName + "</AccountName>").Append("<AccountBank>" + this.iAccountBank + "</AccountBank>").Append("</Account>").Append(this.iTrnxInfo.XMLDocument.ToString()).Append("<ResultNotifyURL>" + this.iResultNotifyURL + "</ResultNotifyURL>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
public virtual string ResultNotifyURL
{
get
{
return this.iResultNotifyURL;
}
set
{
this.iResultNotifyURL = value.Trim();
}
}
public virtual double TrnxAmount
{
get
{
return this.iTrnxAmount;
}
set
{
this.iTrnxAmount = value;
}
}
public virtual string TrnxDate
{
get
{
return this.iTrnxDate;
}
set
{
this.iTrnxDate = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxInfo TrnxInfo
{
get
{
return this.iTrnxInfo;
}
set
{
this.iTrnxInfo = value;
}
}
public virtual string TrnxTime
{
get
{
return this.iTrnxTime;
}
set
{
this.iTrnxTime = value.Trim();
}
}
}
}

+ 484
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/FreezeTransferRequest.cs View File

@ -0,0 +1,484 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class FreezeTransferRequest : TrxRequest
{
public const int ACCOUNT_BANK_URL_LEN = 50;
public const int ACCOUNT_DB_BANK_URL_LEN = 50;
public const int ACCOUNT_DB_NAME_URL_LEN = 50;
public const int ACCOUNT_DB_NO_URL_LEN = 20;
public const int ACCOUNT_NAME_URL_LEN = 50;
public const int ACCOUNT_NO_URL_LEN = 20;
public const int CORPOR_CUSTOMER_URL_LEN = 100;
private string iAccountBank;
private string iAccountDBBank;
private string iAccountDBName;
private string iAccountDBNo;
private string iAccountName;
private string iAccountNo;
private string iCorporationCustomerNo;
private string iMerchantRemarks;
private string iMerchantTrnxNo;
private string iOrginalFreezeNo;
private string iOrginalTrnxSN;
private string iResultNotifyURL;
private double iTrnxAmount;
private string iTrnxDate;
private com.hitrust.b2b.trustpay.client.b2b.TrnxInfo iTrnxInfo;
private string iTrnxTime;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 20;
public const int ORGINAL_FREEZE_NO_URL_LEN = 6;
public const int ORGINAL_TRNX_SN_URL_LEN = 20;
public const int RESULT_NOTIFY_URL_LEN = 200;
public FreezeTransferRequest() : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
}
public FreezeTransferRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
this.TrnxInfo = new com.hitrust.b2b.trustpay.client.b2b.TrnxInfo(aXMLDocument);
this.CorporationCustomerNo = aXMLDocument.getValueNoNull("CorporationCustomerNo");
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
try
{
this.TrnxAmount = double.Parse(aXMLDocument.getValueNoNull("TrnxAmount"));
}
catch (Exception)
{
}
this.TrnxDate = aXMLDocument.getValueNoNull("TrnxDate");
this.TrnxTime = aXMLDocument.getValueNoNull("TrnxTime");
this.OrginalTrnxSN = aXMLDocument.getValueNoNull("OrginalTrnxSN");
this.OrginalFreezeNo = aXMLDocument.getValueNoNull("OrginalFreezeNo");
this.AccountNo = aXMLDocument.getValueNoNull("AccountNo");
this.AccountName = aXMLDocument.getValueNoNull("AccountName");
this.AccountBank = aXMLDocument.getValueNoNull("AccountBank");
this.AccountDBNo = aXMLDocument.getValueNoNull("AccountDBNo");
this.AccountDBName = aXMLDocument.getValueNoNull("AccountDBName");
this.AccountDBBank = aXMLDocument.getValueNoNull("AccountDBBank");
this.ResultNotifyURL = aXMLDocument.getValueNoNull("ResultNotifyURL");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iTrnxInfo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易详细信息!");
}
if (this.iCorporationCustomerNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定企业客户代码!");
}
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iTrnxAmount <= 0.0)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易金额!");
}
if (this.iTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易日期!");
}
if (this.iTrnxTime == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易时间!");
}
if (this.iOrginalTrnxSN == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易流水号!");
}
if (this.iOrginalFreezeNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定原冻结序号!");
}
if (this.iAccountNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账号!");
}
if (this.iAccountName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账户名!");
}
if (this.iAccountBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账户开户行!");
}
if (this.iAccountDBNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账号!");
}
if (this.iAccountDBName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户名!");
}
if (this.iAccountDBBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户开户行!");
}
if (this.iResultNotifyURL == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定支付结果回传网址!");
}
if (!this.iTrnxInfo.Valid)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易详细信息不合法!");
}
if (this.iCorporationCustomerNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iCorporationCustomerNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (this.iOrginalTrnxSN.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalTrnxSN)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (this.iOrginalFreezeNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalFreezeNo)).Length > 6)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (this.iAccountNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账号不合法!");
}
if (this.iAccountName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户名不合法!");
}
if (this.iAccountBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户开户行不合法!");
}
if (this.iAccountDBNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (this.iAccountDBName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (this.iAccountDBBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (!DataVerifier.isValidDate(this.iTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易日期不合法!");
}
if (!DataVerifier.isValidTime(this.iTrnxTime))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易时间不合法!");
}
if (!DataVerifier.isValidAmount(this.iTrnxAmount, 2))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易金额不合法!");
}
if (!DataVerifier.isValidURL(this.iResultNotifyURL))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (this.iResultNotifyURL.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iResultNotifyURL)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string AccountBank
{
get
{
return this.iAccountBank;
}
set
{
this.iAccountBank = value.Trim();
}
}
public virtual string AccountDBBank
{
get
{
return this.iAccountDBBank;
}
set
{
this.iAccountDBBank = value.Trim();
}
}
public virtual string AccountDBName
{
get
{
return this.iAccountDBName;
}
set
{
this.iAccountDBName = value.Trim();
}
}
public virtual string AccountDBNo
{
get
{
return this.iAccountDBNo;
}
set
{
this.iAccountDBNo = value.Trim();
}
}
public virtual string AccountName
{
get
{
return this.iAccountName;
}
set
{
this.iAccountName = value.Trim();
}
}
public virtual string AccountNo
{
get
{
return this.iAccountNo;
}
set
{
this.iAccountNo = value.Trim();
}
}
public virtual string CorporationCustomerNo
{
get
{
return this.iCorporationCustomerNo;
}
set
{
this.iCorporationCustomerNo = value.Trim();
}
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
public virtual string OrginalFreezeNo
{
get
{
return this.iOrginalFreezeNo;
}
set
{
this.iOrginalFreezeNo = value.Trim();
}
}
public virtual string OrginalTrnxSN
{
get
{
return this.iOrginalTrnxSN;
}
set
{
this.iOrginalTrnxSN = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<Corporation>").Append("<CorporationCustomerNo>" + this.iCorporationCustomerNo + "</CorporationCustomerNo>").Append("</Corporation>").Append("<TrxRequest>").Append("<TrxType>FreezeTransfer</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<TrnxAmount>" + DataVerifier.Double2String(this.iTrnxAmount) + "</TrnxAmount>").Append("<TrnxDate>" + this.iTrnxDate + "</TrnxDate>").Append("<TrnxTime>" + this.iTrnxTime + "</TrnxTime>").Append("<OrginalTrnxSN>" + this.iOrginalTrnxSN + "</OrginalTrnxSN>").Append("<OrginalFreezeNo>" + this.iOrginalFreezeNo + "</OrginalFreezeNo>").Append("<Account>").Append("<AccountNo>" + this.iAccountNo + "</AccountNo>").Append("<AccountName>" + this.iAccountName + "</AccountName>").Append("<AccountBank>" + this.iAccountBank + "</AccountBank>").Append("</Account>").Append("<AccountDB>").Append("<AccountDBNo>" + this.iAccountDBNo + "</AccountDBNo>").Append("<AccountDBName>" + this.iAccountDBName + "</AccountDBName>").Append("<AccountDBBank>" + this.iAccountDBBank + "</AccountDBBank>").Append("</AccountDB>").Append(this.iTrnxInfo.XMLDocument.ToString()).Append("<ResultNotifyURL>" + this.iResultNotifyURL + "</ResultNotifyURL>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
public virtual string ResultNotifyURL
{
get
{
return this.iResultNotifyURL;
}
set
{
this.iResultNotifyURL = value.Trim();
}
}
public virtual double TrnxAmount
{
get
{
return this.iTrnxAmount;
}
set
{
this.iTrnxAmount = value;
}
}
public virtual string TrnxDate
{
get
{
return this.iTrnxDate;
}
set
{
this.iTrnxDate = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxInfo TrnxInfo
{
get
{
return this.iTrnxInfo;
}
set
{
this.iTrnxInfo = value;
}
}
public virtual string TrnxTime
{
get
{
return this.iTrnxTime;
}
set
{
this.iTrnxTime = value.Trim();
}
}
}
}

+ 310
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/FundTransferRequest.cs View File

@ -0,0 +1,310 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class FundTransferRequest : TrxRequest
{
public const int ACCOUNT_BANK_URL_LEN = 50;
public const int ACCOUNT_NAME_URL_LEN = 50;
public const int ACCOUNT_NO_URL_LEN = 20;
private string iAccountDBBank;
private string iAccountDBName;
private string iAccountDBNo;
private string iMerchantRemarks;
private string iMerchantTrnxNo;
private string iResultNotifyURL;
private double iTrnxAmount;
private string iTrnxDate;
private com.hitrust.b2b.trustpay.client.b2b.TrnxInfo iTrnxInfo;
private string iTrnxTime;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 100;
public const int RESULT_NOTIFY_URL_LEN = 200;
public FundTransferRequest() : base("B2B")
{
this.iTrnxInfo = null;
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
}
public FundTransferRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iTrnxInfo = null;
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
this.TrnxInfo = new com.hitrust.b2b.trustpay.client.b2b.TrnxInfo(aXMLDocument);
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
try
{
this.TrnxAmount = double.Parse(aXMLDocument.getValueNoNull("TrnxAmount"));
}
catch (Exception)
{
}
this.TrnxDate = aXMLDocument.getValueNoNull("TrnxDate");
this.TrnxTime = aXMLDocument.getValueNoNull("TrnxTime");
this.AccountDBNo = aXMLDocument.getValueNoNull("AccountDBNo");
this.AccountDBName = aXMLDocument.getValueNoNull("AccountDBName");
this.AccountDBBank = aXMLDocument.getValueNoNull("AccountDBBank");
this.ResultNotifyURL = aXMLDocument.getValueNoNull("ResultNotifyURL");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iTrnxInfo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易详细信息!");
}
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iTrnxAmount <= 0.0)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易金额!");
}
if (this.iTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易日期!");
}
if (this.iTrnxTime == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易时间!");
}
if (this.iAccountDBNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账号!");
}
if (this.iAccountDBName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户名!");
}
if (this.iAccountDBBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户开户行!");
}
if (this.iResultNotifyURL == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易结果回传网址!");
}
if (!this.iTrnxInfo.Valid)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易详细信息不合法!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (this.iAccountDBNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (this.iAccountDBName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (this.iAccountDBBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (!DataVerifier.isValidDate(this.iTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易日期不合法!");
}
if (!DataVerifier.isValidTime(this.iTrnxTime))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易时间不合法!");
}
if (!DataVerifier.isValidAmount(this.iTrnxAmount, 2))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易金额不合法!");
}
if (!DataVerifier.isValidURL(this.iResultNotifyURL))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (this.iResultNotifyURL.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iResultNotifyURL)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string AccountDBBank
{
get
{
return this.iAccountDBBank;
}
set
{
this.iAccountDBBank = value.Trim();
}
}
public virtual string AccountDBName
{
get
{
return this.iAccountDBName;
}
set
{
this.iAccountDBName = value.Trim();
}
}
public virtual string AccountDBNo
{
get
{
return this.iAccountDBNo;
}
set
{
this.iAccountDBNo = value.Trim();
}
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<TrxRequest>").Append("<TrxType>FundTransfer</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<TrnxAmount>" + DataVerifier.Double2String(this.iTrnxAmount) + "</TrnxAmount>").Append("<TrnxDate>" + this.iTrnxDate + "</TrnxDate>").Append("<TrnxTime>" + this.iTrnxTime + "</TrnxTime>").Append("<AccountDB>").Append("<AccountDBNo>" + this.iAccountDBNo + "</AccountDBNo>").Append("<AccountDBName>" + this.iAccountDBName + "</AccountDBName>").Append("<AccountDBBank>" + this.iAccountDBBank + "</AccountDBBank>").Append("</AccountDB>").Append(this.iTrnxInfo.XMLDocument.ToString()).Append("<ResultNotifyURL>" + this.iResultNotifyURL + "</ResultNotifyURL>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
public virtual string ResultNotifyURL
{
get
{
return this.iResultNotifyURL;
}
set
{
this.iResultNotifyURL = value.Trim();
}
}
public virtual double TrnxAmount
{
get
{
return this.iTrnxAmount;
}
set
{
this.iTrnxAmount = value;
}
}
public virtual string TrnxDate
{
get
{
return this.iTrnxDate;
}
set
{
this.iTrnxDate = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxInfo TrnxInfo
{
get
{
return this.iTrnxInfo;
}
set
{
this.iTrnxInfo = value;
}
}
public virtual string TrnxTime
{
get
{
return this.iTrnxTime;
}
set
{
this.iTrnxTime = value.Trim();
}
}
}
}

+ 484
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/PartFreezeTransferRequest.cs View File

@ -0,0 +1,484 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class PartFreezeTransferRequest : TrxRequest
{
public const int ACCOUNT_BANK_URL_LEN = 50;
public const int ACCOUNT_DB_BANK_URL_LEN = 50;
public const int ACCOUNT_DB_NAME_URL_LEN = 50;
public const int ACCOUNT_DB_NO_URL_LEN = 20;
public const int ACCOUNT_NAME_URL_LEN = 50;
public const int ACCOUNT_NO_URL_LEN = 20;
public const int CORPOR_CUSTOMER_URL_LEN = 100;
private string iAccountBank;
private string iAccountDBBank;
private string iAccountDBName;
private string iAccountDBNo;
private string iAccountName;
private string iAccountNo;
private string iCorporationCustomerNo;
private string iMerchantRemarks;
private string iMerchantTrnxNo;
private string iOrginalFreezeNo;
private string iOrginalTrnxSN;
private string iResultNotifyURL;
private double iTrnxAmount;
private string iTrnxDate;
private com.hitrust.b2b.trustpay.client.b2b.TrnxInfo iTrnxInfo;
private string iTrnxTime;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 20;
public const int ORGINAL_FREEZE_NO_URL_LEN = 6;
public const int ORGINAL_TRNX_SN_URL_LEN = 20;
public const int RESULT_NOTIFY_URL_LEN = 200;
public PartFreezeTransferRequest() : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
}
public PartFreezeTransferRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
this.TrnxInfo = new com.hitrust.b2b.trustpay.client.b2b.TrnxInfo(aXMLDocument);
this.CorporationCustomerNo = aXMLDocument.getValueNoNull("CorporationCustomerNo");
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
try
{
this.TrnxAmount = double.Parse(aXMLDocument.getValueNoNull("TrnxAmount"));
}
catch (Exception)
{
}
this.TrnxDate = aXMLDocument.getValueNoNull("TrnxDate");
this.TrnxTime = aXMLDocument.getValueNoNull("TrnxTime");
this.OrginalTrnxSN = aXMLDocument.getValueNoNull("OrginalTrnxSN");
this.OrginalFreezeNo = aXMLDocument.getValueNoNull("OrginalFreezeNo");
this.AccountNo = aXMLDocument.getValueNoNull("AccountNo");
this.AccountName = aXMLDocument.getValueNoNull("AccountName");
this.AccountBank = aXMLDocument.getValueNoNull("AccountBank");
this.AccountDBNo = aXMLDocument.getValueNoNull("AccountDBNo");
this.AccountDBName = aXMLDocument.getValueNoNull("AccountDBName");
this.AccountDBBank = aXMLDocument.getValueNoNull("AccountDBBank");
this.ResultNotifyURL = aXMLDocument.getValueNoNull("ResultNotifyURL");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iTrnxInfo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易详细信息!");
}
if (this.iCorporationCustomerNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定企业客户代码!");
}
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iTrnxAmount <= 0.0)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易金额!");
}
if (this.iTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易日期!");
}
if (this.iTrnxTime == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易时间!");
}
if (this.iOrginalTrnxSN == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易流水号!");
}
if (this.iOrginalFreezeNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定原冻结序号!");
}
if (this.iAccountNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账号!");
}
if (this.iAccountName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账户名!");
}
if (this.iAccountBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账户开户行!");
}
if (this.iAccountDBNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账号!");
}
if (this.iAccountDBName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户名!");
}
if (this.iAccountDBBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户开户行!");
}
if (this.iResultNotifyURL == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易结果回传网址!");
}
if (!this.iTrnxInfo.Valid)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易详细信息不合法!");
}
if (this.iCorporationCustomerNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iCorporationCustomerNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (this.iOrginalTrnxSN.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalTrnxSN)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (this.iOrginalFreezeNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalFreezeNo)).Length > 6)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (this.iAccountNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账号不合法!");
}
if (this.iAccountName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户名不合法!");
}
if (this.iAccountBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户开户行不合法!");
}
if (this.iAccountDBNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (this.iAccountDBName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (this.iAccountDBBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (!DataVerifier.isValidDate(this.iTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易日期不合法!");
}
if (!DataVerifier.isValidTime(this.iTrnxTime))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易时间不合法!");
}
if (!DataVerifier.isValidAmount(this.iTrnxAmount, 2))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易金额不合法!");
}
if (!DataVerifier.isValidURL(this.iResultNotifyURL))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (this.iResultNotifyURL.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iResultNotifyURL)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string AccountBank
{
get
{
return this.iAccountBank;
}
set
{
this.iAccountBank = value.Trim();
}
}
public virtual string AccountDBBank
{
get
{
return this.iAccountDBBank;
}
set
{
this.iAccountDBBank = value.Trim();
}
}
public virtual string AccountDBName
{
get
{
return this.iAccountDBName;
}
set
{
this.iAccountDBName = value.Trim();
}
}
public virtual string AccountDBNo
{
get
{
return this.iAccountDBNo;
}
set
{
this.iAccountDBNo = value.Trim();
}
}
public virtual string AccountName
{
get
{
return this.iAccountName;
}
set
{
this.iAccountName = value.Trim();
}
}
public virtual string AccountNo
{
get
{
return this.iAccountNo;
}
set
{
this.iAccountNo = value.Trim();
}
}
public virtual string CorporationCustomerNo
{
get
{
return this.iCorporationCustomerNo;
}
set
{
this.iCorporationCustomerNo = value.Trim();
}
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
public virtual string OrginalFreezeNo
{
get
{
return this.iOrginalFreezeNo;
}
set
{
this.iOrginalFreezeNo = value.Trim();
}
}
public virtual string OrginalTrnxSN
{
get
{
return this.iOrginalTrnxSN;
}
set
{
this.iOrginalTrnxSN = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<Corporation>").Append("<CorporationCustomerNo>" + this.iCorporationCustomerNo + "</CorporationCustomerNo>").Append("</Corporation>").Append("<TrxRequest>").Append("<TrxType>PartFreezeTransfer</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<TrnxAmount>" + DataVerifier.Double2String(this.iTrnxAmount) + "</TrnxAmount>").Append("<TrnxDate>" + this.iTrnxDate + "</TrnxDate>").Append("<TrnxTime>" + this.iTrnxTime + "</TrnxTime>").Append("<OrginalTrnxSN>" + this.iOrginalTrnxSN + "</OrginalTrnxSN>").Append("<OrginalFreezeNo>" + this.iOrginalFreezeNo + "</OrginalFreezeNo>").Append("<Account>").Append("<AccountNo>" + this.iAccountNo + "</AccountNo>").Append("<AccountName>" + this.iAccountName + "</AccountName>").Append("<AccountBank>" + this.iAccountBank + "</AccountBank>").Append("</Account>").Append("<AccountDB>").Append("<AccountDBNo>" + this.iAccountDBNo + "</AccountDBNo>").Append("<AccountDBName>" + this.iAccountDBName + "</AccountDBName>").Append("<AccountDBBank>" + this.iAccountDBBank + "</AccountDBBank>").Append("</AccountDB>").Append(this.iTrnxInfo.XMLDocument.ToString()).Append("<ResultNotifyURL>" + this.iResultNotifyURL + "</ResultNotifyURL>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
public virtual string ResultNotifyURL
{
get
{
return this.iResultNotifyURL;
}
set
{
this.iResultNotifyURL = value.Trim();
}
}
public virtual double TrnxAmount
{
get
{
return this.iTrnxAmount;
}
set
{
this.iTrnxAmount = value;
}
}
public virtual string TrnxDate
{
get
{
return this.iTrnxDate;
}
set
{
this.iTrnxDate = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxInfo TrnxInfo
{
get
{
return this.iTrnxInfo;
}
set
{
this.iTrnxInfo = value;
}
}
public virtual string TrnxTime
{
get
{
return this.iTrnxTime;
}
set
{
this.iTrnxTime = value.Trim();
}
}
}
}

+ 397
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/PartUnFreezeRequest.cs View File

@ -0,0 +1,397 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class PartUnFreezeRequest : TrxRequest
{
public const int ACCOUNT_BANK_URL_LEN = 50;
public const int ACCOUNT_NAME_URL_LEN = 50;
public const int ACCOUNT_NO_URL_LEN = 20;
public const int CORPOR_CUSTOMER_URL_LEN = 100;
private string iAccountBank;
private string iAccountName;
private string iAccountNo;
private string iCorporationCustomerNo;
private string iMerchantRemarks;
private string iMerchantTrnxNo;
private string iOrginalFreezeNo;
private string iOrginalTrnxSN;
private string iResultNotifyURL;
private double iTrnxAmount;
private string iTrnxDate;
private com.hitrust.b2b.trustpay.client.b2b.TrnxInfo iTrnxInfo;
private string iTrnxTime;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 20;
public const int ORGINAL_FREEZE_NO_URL_LEN = 6;
public const int ORGINAL_TRNX_SN_URL_LEN = 20;
public const int RESULT_NOTIFY_URL_LEN = 200;
public PartUnFreezeRequest() : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
}
public PartUnFreezeRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
this.TrnxInfo = new com.hitrust.b2b.trustpay.client.b2b.TrnxInfo(aXMLDocument);
this.CorporationCustomerNo = aXMLDocument.getValueNoNull("CorporationCustomerNo");
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
try
{
this.TrnxAmount = double.Parse(aXMLDocument.getValueNoNull("TrnxAmount"));
}
catch (Exception)
{
}
this.TrnxDate = aXMLDocument.getValueNoNull("TrnxDate");
this.TrnxTime = aXMLDocument.getValueNoNull("TrnxTime");
this.OrginalTrnxSN = aXMLDocument.getValueNoNull("OrginalTrnxSN");
this.OrginalFreezeNo = aXMLDocument.getValueNoNull("OrginalFreezeNo");
this.AccountNo = aXMLDocument.getValueNoNull("AccountNo");
this.AccountName = aXMLDocument.getValueNoNull("AccountName");
this.AccountBank = aXMLDocument.getValueNoNull("AccountBank");
this.ResultNotifyURL = aXMLDocument.getValueNoNull("ResultNotifyURL");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iTrnxInfo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易详细信息!");
}
if (this.iCorporationCustomerNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定企业客户代码!");
}
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iTrnxAmount <= 0.0)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易金额!");
}
if (this.iTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易日期!");
}
if (this.iTrnxTime == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易时间!");
}
if (this.iOrginalTrnxSN == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易流水号!");
}
if (this.iOrginalFreezeNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定原冻结序号!");
}
if (this.iAccountNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账号!");
}
if (this.iAccountName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账户名!");
}
if (this.iAccountBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账户开户行!");
}
if (this.iResultNotifyURL == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易结果回传网址!");
}
if (!this.iTrnxInfo.Valid)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易详细信息不合法!");
}
if (this.iCorporationCustomerNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iCorporationCustomerNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (this.iOrginalTrnxSN.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalTrnxSN)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (this.iOrginalFreezeNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalFreezeNo)).Length > 6)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (this.iAccountNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账号不合法!");
}
if (this.iAccountName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户名不合法!");
}
if (this.iAccountBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户开户行不合法!");
}
if (!DataVerifier.isValidDate(this.iTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易日期不合法!");
}
if (!DataVerifier.isValidTime(this.iTrnxTime))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易时间不合法!");
}
if (!DataVerifier.isValidAmount(this.iTrnxAmount, 2))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易金额不合法!");
}
if (!DataVerifier.isValidURL(this.iResultNotifyURL))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (this.iResultNotifyURL.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iResultNotifyURL)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string AccountBank
{
get
{
return this.iAccountBank;
}
set
{
this.iAccountBank = value.Trim();
}
}
public virtual string AccountName
{
get
{
return this.iAccountName;
}
set
{
this.iAccountName = value.Trim();
}
}
public virtual string AccountNo
{
get
{
return this.iAccountNo;
}
set
{
this.iAccountNo = value.Trim();
}
}
public virtual string CorporationCustomerNo
{
get
{
return this.iCorporationCustomerNo;
}
set
{
this.iCorporationCustomerNo = value.Trim();
}
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
public virtual string OrginalFreezeNo
{
get
{
return this.iOrginalFreezeNo;
}
set
{
this.iOrginalFreezeNo = value.Trim();
}
}
public virtual string OrginalTrnxSN
{
get
{
return this.iOrginalTrnxSN;
}
set
{
this.iOrginalTrnxSN = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<Corporation>").Append("<CorporationCustomerNo>" + this.iCorporationCustomerNo + "</CorporationCustomerNo>").Append("</Corporation>").Append("<TrxRequest>").Append("<TrxType>PartUnFreeze</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<TrnxAmount>" + DataVerifier.Double2String(this.iTrnxAmount) + "</TrnxAmount>").Append("<TrnxDate>" + this.iTrnxDate + "</TrnxDate>").Append("<TrnxTime>" + this.iTrnxTime + "</TrnxTime>").Append("<OrginalTrnxSN>" + this.iOrginalTrnxSN + "</OrginalTrnxSN>").Append("<OrginalFreezeNo>" + this.iOrginalFreezeNo + "</OrginalFreezeNo>").Append("<Account>").Append("<AccountNo>" + this.iAccountNo + "</AccountNo>").Append("<AccountName>" + this.iAccountName + "</AccountName>").Append("<AccountBank>" + this.iAccountBank + "</AccountBank>").Append("</Account>").Append(this.iTrnxInfo.XMLDocument.ToString()).Append("<ResultNotifyURL>" + this.iResultNotifyURL + "</ResultNotifyURL>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
public virtual string ResultNotifyURL
{
get
{
return this.iResultNotifyURL;
}
set
{
this.iResultNotifyURL = value.Trim();
}
}
public virtual double TrnxAmount
{
get
{
return this.iTrnxAmount;
}
set
{
this.iTrnxAmount = value;
}
}
public virtual string TrnxDate
{
get
{
return this.iTrnxDate;
}
set
{
this.iTrnxDate = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxInfo TrnxInfo
{
get
{
return this.iTrnxInfo;
}
set
{
this.iTrnxInfo = value;
}
}
public virtual string TrnxTime
{
get
{
return this.iTrnxTime;
}
set
{
this.iTrnxTime = value.Trim();
}
}
}
}

+ 484
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/PayFeeRequest.cs View File

@ -0,0 +1,484 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class PayFeeRequest : TrxRequest
{
public const int ACCOUNT_BANK_URL_LEN = 50;
public const int ACCOUNT_DB_BANK_URL_LEN = 50;
public const int ACCOUNT_DB_NAME_URL_LEN = 50;
public const int ACCOUNT_DB_NO_URL_LEN = 20;
public const int ACCOUNT_NAME_URL_LEN = 50;
public const int ACCOUNT_NO_URL_LEN = 20;
public const int CORPOR_CUSTOMER_URL_LEN = 100;
private string iAccountBank;
private string iAccountDBBank;
private string iAccountDBName;
private string iAccountDBNo;
private string iAccountName;
private string iAccountNo;
private string iCorporationCustomerNo;
private string iMerchantRemarks;
private string iMerchantTrnxNo;
private string iOrginalFreezeNo;
private string iOrginalTrnxSN;
private string iResultNotifyURL;
private double iTrnxAmount;
private string iTrnxDate;
private com.hitrust.b2b.trustpay.client.b2b.TrnxInfo iTrnxInfo;
private string iTrnxTime;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 20;
public const int ORGINAL_FREEZE_NO_URL_LEN = 6;
public const int ORGINAL_TRNX_SN_URL_LEN = 20;
public const int RESULT_NOTIFY_URL_LEN = 200;
public PayFeeRequest() : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
}
public PayFeeRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iAccountDBNo = "";
this.iAccountDBName = "";
this.iAccountDBBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
this.TrnxInfo = new com.hitrust.b2b.trustpay.client.b2b.TrnxInfo(aXMLDocument);
this.CorporationCustomerNo = aXMLDocument.getValueNoNull("CorporationCustomerNo");
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
try
{
this.TrnxAmount = double.Parse(aXMLDocument.getValueNoNull("TrnxAmount"));
}
catch (Exception)
{
}
this.TrnxDate = aXMLDocument.getValueNoNull("TrnxDate");
this.TrnxTime = aXMLDocument.getValueNoNull("TrnxTime");
this.OrginalTrnxSN = aXMLDocument.getValueNoNull("OrginalTrnxSN");
this.OrginalFreezeNo = aXMLDocument.getValueNoNull("OrginalFreezeNo");
this.AccountNo = aXMLDocument.getValueNoNull("AccountNo");
this.AccountName = aXMLDocument.getValueNoNull("AccountName");
this.AccountBank = aXMLDocument.getValueNoNull("AccountBank");
this.AccountDBNo = aXMLDocument.getValueNoNull("AccountDBNo");
this.AccountDBName = aXMLDocument.getValueNoNull("AccountDBName");
this.AccountDBBank = aXMLDocument.getValueNoNull("AccountDBBank");
this.ResultNotifyURL = aXMLDocument.getValueNoNull("ResultNotifyURL");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iTrnxInfo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易详细信息!");
}
if (this.iCorporationCustomerNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定企业客户代码!");
}
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iTrnxAmount <= 0.0)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易金额!");
}
if (this.iTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易日期!");
}
if (this.iTrnxTime == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易时间!");
}
if (this.iOrginalTrnxSN == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易流水号!");
}
if (this.iOrginalFreezeNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定原冻结序号!");
}
if (this.iAccountNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账号!");
}
if (this.iAccountName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账户名!");
}
if (this.iAccountBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定付款方账户开户行!");
}
if (this.iAccountDBNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账号!");
}
if (this.iAccountDBName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户名!");
}
if (this.iAccountDBBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定收款方账户开户行!");
}
if (this.iResultNotifyURL == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易结果回传网址!");
}
if (!this.iTrnxInfo.Valid)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易详细信息不合法!");
}
if (this.iCorporationCustomerNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iCorporationCustomerNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (this.iOrginalTrnxSN.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalTrnxSN)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (this.iOrginalFreezeNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalFreezeNo)).Length > 6)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (this.iAccountNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账号不合法!");
}
if (this.iAccountName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户名不合法!");
}
if (this.iAccountBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "付款方账户开户行不合法!");
}
if (this.iAccountDBNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账号不合法!");
}
if (this.iAccountDBName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户名不合法!");
}
if (this.iAccountDBBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountDBBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "收款方账户开户行不合法!");
}
if (!DataVerifier.isValidDate(this.iTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易日期不合法!");
}
if (!DataVerifier.isValidTime(this.iTrnxTime))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易时间不合法!");
}
if (!DataVerifier.isValidAmount(this.iTrnxAmount, 2))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易金额不合法!");
}
if (!DataVerifier.isValidURL(this.iResultNotifyURL))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (this.iResultNotifyURL.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iResultNotifyURL)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string AccountBank
{
get
{
return this.iAccountBank;
}
set
{
this.iAccountBank = value.Trim();
}
}
public virtual string AccountDBBank
{
get
{
return this.iAccountDBBank;
}
set
{
this.iAccountDBBank = value.Trim();
}
}
public virtual string AccountDBName
{
get
{
return this.iAccountDBName;
}
set
{
this.iAccountDBName = value.Trim();
}
}
public virtual string AccountDBNo
{
get
{
return this.iAccountDBNo;
}
set
{
this.iAccountDBNo = value.Trim();
}
}
public virtual string AccountName
{
get
{
return this.iAccountName;
}
set
{
this.iAccountName = value.Trim();
}
}
public virtual string AccountNo
{
get
{
return this.iAccountNo;
}
set
{
this.iAccountNo = value.Trim();
}
}
public virtual string CorporationCustomerNo
{
get
{
return this.iCorporationCustomerNo;
}
set
{
this.iCorporationCustomerNo = value.Trim();
}
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
public virtual string OrginalFreezeNo
{
get
{
return this.iOrginalFreezeNo;
}
set
{
this.iOrginalFreezeNo = value.Trim();
}
}
public virtual string OrginalTrnxSN
{
get
{
return this.iOrginalTrnxSN;
}
set
{
this.iOrginalTrnxSN = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<Corporation>").Append("<CorporationCustomerNo>" + this.iCorporationCustomerNo + "</CorporationCustomerNo>").Append("</Corporation>").Append("<TrxRequest>").Append("<TrxType>PayFee</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<TrnxAmount>" + DataVerifier.Double2String(this.iTrnxAmount) + "</TrnxAmount>").Append("<TrnxDate>" + this.iTrnxDate + "</TrnxDate>").Append("<TrnxTime>" + this.iTrnxTime + "</TrnxTime>").Append("<OrginalTrnxSN>" + this.iOrginalTrnxSN + "</OrginalTrnxSN>").Append("<OrginalFreezeNo>" + this.iOrginalFreezeNo + "</OrginalFreezeNo>").Append("<Account>").Append("<AccountNo>" + this.iAccountNo + "</AccountNo>").Append("<AccountName>" + this.iAccountName + "</AccountName>").Append("<AccountBank>" + this.iAccountBank + "</AccountBank>").Append("</Account>").Append("<AccountDB>").Append("<AccountDBNo>" + this.iAccountDBNo + "</AccountDBNo>").Append("<AccountDBName>" + this.iAccountDBName + "</AccountDBName>").Append("<AccountDBBank>" + this.iAccountDBBank + "</AccountDBBank>").Append("</AccountDB>").Append(this.iTrnxInfo.XMLDocument.ToString()).Append("<ResultNotifyURL>" + this.iResultNotifyURL + "</ResultNotifyURL>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
public virtual string ResultNotifyURL
{
get
{
return this.iResultNotifyURL;
}
set
{
this.iResultNotifyURL = value.Trim();
}
}
public virtual double TrnxAmount
{
get
{
return this.iTrnxAmount;
}
set
{
this.iTrnxAmount = value;
}
}
public virtual string TrnxDate
{
get
{
return this.iTrnxDate;
}
set
{
this.iTrnxDate = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxInfo TrnxInfo
{
get
{
return this.iTrnxInfo;
}
set
{
this.iTrnxInfo = value;
}
}
public virtual string TrnxTime
{
get
{
return this.iTrnxTime;
}
set
{
this.iTrnxTime = value.Trim();
}
}
}
}

+ 88
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/QueryTrnxRequest.cs View File

@ -0,0 +1,88 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class QueryTrnxRequest : TrxRequest
{
private string iMerchantRemarks;
private string iMerchantTrnxNo;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 100;
public QueryTrnxRequest() : base("B2B")
{
this.iMerchantTrnxNo = "";
this.iMerchantRemarks = "";
}
public QueryTrnxRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iMerchantTrnxNo = "";
this.iMerchantRemarks = "";
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<TrxRequest>").Append("<TrxType>QueryTrnx</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
}
}

+ 106
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxInfo.cs View File

@ -0,0 +1,106 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class TrnxInfo
{
private com.hitrust.b2b.trustpay.client.b2b.TrnxItems iTrnxItems;
private string iTrnxOpr;
private com.hitrust.b2b.trustpay.client.b2b.TrnxRemarks iTrnxRemarks;
public const int TRNXOPR_URL_LEN = 20;
public TrnxInfo()
{
this.iTrnxOpr = "";
this.iTrnxItems = null;
this.iTrnxRemarks = null;
}
public TrnxInfo(com.hitrust.b2b.trustpay.client.XMLDocument aXMLDocument)
{
this.iTrnxOpr = "";
this.iTrnxItems = null;
this.iTrnxRemarks = null;
this.TrnxOpr = aXMLDocument.getValueNoNull("TrnxOpr");
if (this.TrnxItems != null)
{
this.TrnxItems = new com.hitrust.b2b.trustpay.client.b2b.TrnxItems(aXMLDocument);
}
if (this.TrnxRemarks != null)
{
this.TrnxRemarks = new com.hitrust.b2b.trustpay.client.b2b.TrnxRemarks(aXMLDocument);
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxItems TrnxItems
{
get
{
return this.iTrnxItems;
}
set
{
this.iTrnxItems = value;
}
}
public virtual string TrnxOpr
{
get
{
return this.iTrnxOpr;
}
set
{
this.iTrnxOpr = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxRemarks TrnxRemarks
{
get
{
return this.iTrnxRemarks;
}
set
{
this.iTrnxRemarks = value;
}
}
public virtual bool Valid
{
get
{
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iTrnxOpr)).Length > 20)
{
return false;
}
com.hitrust.b2b.trustpay.client.b2b.TrnxItems trnxItems = this.TrnxItems;
if ((trnxItems != null) && !trnxItems.Valid)
{
return false;
}
com.hitrust.b2b.trustpay.client.b2b.TrnxRemarks trnxRemarks = this.TrnxRemarks;
if ((trnxRemarks != null) && !trnxRemarks.Valid)
{
return false;
}
return true;
}
}
public virtual com.hitrust.b2b.trustpay.client.XMLDocument XMLDocument
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<TrnxInfo>").Append("<TrnxOpr>" + this.iTrnxOpr + "</TrnxOpr>").Append(this.iTrnxRemarks.XMLDocument).Append(this.iTrnxItems.XMLDocument).Append("</TrnxInfo>");
return new com.hitrust.b2b.trustpay.client.XMLDocument(builder.ToString());
}
}
}
}

+ 181
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxItem.cs View File

@ -0,0 +1,181 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class TrnxItem
{
private double iAmount;
private string iProductID;
private string iProductName;
private int iQty;
private double iUnitPrice;
public const int PRODUCT_ID_LEN = 20;
public const int PRODUCT_NAME_LEN = 50;
public TrnxItem()
{
this.iProductID = "";
this.iProductName = "";
this.iUnitPrice = 0.0;
this.iQty = 0;
this.iAmount = 0.0;
}
public TrnxItem(com.hitrust.b2b.trustpay.client.XMLDocument aXMLDocument)
{
this.iProductID = "";
this.iProductName = "";
this.iUnitPrice = 0.0;
this.iQty = 0;
this.iAmount = 0.0;
this.ProductID = aXMLDocument.getValueNoNull("ProductID");
this.ProductName = aXMLDocument.getValueNoNull("ProductName");
try
{
this.UnitPrice = double.Parse(aXMLDocument.getValueNoNull("UnitPrice"));
}
catch (Exception)
{
}
try
{
this.Qty = int.Parse(aXMLDocument.getValueNoNull("Qty"));
}
catch (Exception)
{
}
}
public TrnxItem(string aProductID, string aProductName, double aUnitPrice, int aQty)
{
this.iProductID = "";
this.iProductName = "";
this.iUnitPrice = 0.0;
this.iQty = 0;
this.iAmount = 0.0;
this.ProductID = aProductID;
this.ProductName = aProductName;
this.UnitPrice = aUnitPrice;
this.Qty = aQty;
}
public virtual double Amount
{
get
{
this.Amount = this.UnitPrice * this.Qty;
return (this.iUnitPrice * this.iQty);
}
set
{
this.Amount = this.UnitPrice * this.Qty;
this.iAmount = value;
}
}
public virtual string ProductID
{
get
{
return this.iProductID;
}
set
{
this.iProductID = value.Trim();
}
}
public virtual string ProductName
{
get
{
return this.iProductName;
}
set
{
this.iProductName = value.Trim();
}
}
public virtual int Qty
{
get
{
return this.iQty;
}
set
{
this.iQty = value;
}
}
public virtual double UnitPrice
{
get
{
return this.iUnitPrice;
}
set
{
this.iUnitPrice = value;
}
}
public virtual bool Valid
{
get
{
if (this.iProductID == null)
{
return false;
}
if (this.iProductName == null)
{
return false;
}
if (this.iUnitPrice <= 0.0)
{
return false;
}
if (this.iQty <= 0)
{
return false;
}
if (this.iProductID.Length == 0)
{
return false;
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iProductID)).Length > 20)
{
return false;
}
if (this.iProductName.Length == 0)
{
return false;
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iProductName)).Length > 50)
{
return false;
}
if (!DataVerifier.isValidAmount(this.iUnitPrice, 2))
{
return false;
}
return true;
}
}
public virtual com.hitrust.b2b.trustpay.client.XMLDocument XMLDocument
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<TrnxItem>").Append("<ProductID>" + this.iProductID + "</ProductID>").Append("<ProductName>" + this.iProductName + "</ProductName>").Append("<UnitPrice>" + DataVerifier.Double2String(this.iUnitPrice) + "</UnitPrice>").Append("<Qty>" + this.iQty + "</Qty>").Append("</TrnxItem>");
return new com.hitrust.b2b.trustpay.client.XMLDocument(builder.ToString());
}
}
}
}

+ 68
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxItems.cs View File

@ -0,0 +1,68 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Collections;
using System.Text;
public class TrnxItems
{
private ArrayList iTrnxItems;
public TrnxItems()
{
this.iTrnxItems = null;
this.iTrnxItems = new ArrayList();
}
public TrnxItems(com.hitrust.b2b.trustpay.client.XMLDocument aXMLDocument)
{
this.iTrnxItems = null;
this.iTrnxItems = new ArrayList();
ArrayList list = aXMLDocument.getDocuments("TrnxItem");
for (int i = 0; i < list.Count; i++)
{
this.addTrnxItem(new TrnxItem((com.hitrust.b2b.trustpay.client.XMLDocument) list[i]));
}
}
public virtual TrnxItems addTrnxItem(TrnxItem aTrnxItem)
{
this.iTrnxItems.Add(aTrnxItem);
return this;
}
public virtual bool Valid
{
get
{
for (int i = 0; i < this.iTrnxItems.Count; i++)
{
TrnxItem item = (TrnxItem) this.iTrnxItems[i];
if (!item.Valid)
{
return false;
}
}
return true;
}
}
public virtual com.hitrust.b2b.trustpay.client.XMLDocument XMLDocument
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<TrnxItems>");
for (int i = 0; i < this.iTrnxItems.Count; i++)
{
TrnxItem item = (TrnxItem) this.iTrnxItems[i];
builder.Append(item.XMLDocument.ToString());
}
builder.Append("</TrnxItems>");
return new com.hitrust.b2b.trustpay.client.XMLDocument(builder.ToString());
}
}
}
}

+ 103
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxRemark.cs View File

@ -0,0 +1,103 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class TrnxRemark
{
private string iKey;
private string iValue;
public const int KEY_LEN = 100;
public const int VALUE_LEN = 100;
public TrnxRemark()
{
this.iKey = "";
this.iValue = "";
}
public TrnxRemark(com.hitrust.b2b.trustpay.client.XMLDocument aXMLDocument)
{
this.iKey = "";
this.iValue = "";
this.Key = aXMLDocument.getValueNoNull("Key");
this.Value = aXMLDocument.getValueNoNull("Value");
}
public TrnxRemark(string aKey, string aValue)
{
this.iKey = "";
this.iValue = "";
this.Key = aKey;
this.Value = aValue;
}
public virtual string Key
{
get
{
return this.iKey;
}
set
{
this.iKey = value.Trim();
}
}
public virtual bool Valid
{
get
{
if (this.iKey == null)
{
return false;
}
if (this.iValue == null)
{
return false;
}
if (this.iKey.Length == 0)
{
return false;
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iKey)).Length > 100)
{
return false;
}
if (this.iValue.Length == 0)
{
return false;
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iValue)).Length > 100)
{
return false;
}
return true;
}
}
public virtual string Value
{
get
{
return this.iValue;
}
set
{
this.iValue = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.XMLDocument XMLDocument
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<Remark>").Append("<Key>" + this.iKey + "</Key>").Append("<Value>" + this.iValue + "</Value>").Append("</Remark>");
return new com.hitrust.b2b.trustpay.client.XMLDocument(builder.ToString());
}
}
}
}

+ 68
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxRemarks.cs View File

@ -0,0 +1,68 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Collections;
using System.Text;
public class TrnxRemarks
{
private ArrayList iTrnxRemarks;
public TrnxRemarks()
{
this.iTrnxRemarks = null;
this.iTrnxRemarks = new ArrayList();
}
public TrnxRemarks(com.hitrust.b2b.trustpay.client.XMLDocument aXMLDocument)
{
this.iTrnxRemarks = null;
this.iTrnxRemarks = new ArrayList();
ArrayList list = aXMLDocument.getDocuments("TrnxRemark");
for (int i = 0; i < list.Count; i++)
{
this.addTrnxRemark(new TrnxRemark((com.hitrust.b2b.trustpay.client.XMLDocument) list[i]));
}
}
public virtual TrnxRemarks addTrnxRemark(TrnxRemark aTrnxRemark)
{
this.iTrnxRemarks.Add(aTrnxRemark);
return this;
}
public virtual bool Valid
{
get
{
for (int i = 0; i < this.iTrnxRemarks.Count; i++)
{
TrnxRemark remark = (TrnxRemark) this.iTrnxRemarks[i];
if (!remark.Valid)
{
return false;
}
}
return true;
}
}
public virtual com.hitrust.b2b.trustpay.client.XMLDocument XMLDocument
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<TrnxRemarks>");
for (int i = 0; i < this.iTrnxRemarks.Count; i++)
{
TrnxRemark remark = (TrnxRemark) this.iTrnxRemarks[i];
builder.Append(remark.XMLDocument.ToString());
}
builder.Append("</TrnxRemarks>");
return new com.hitrust.b2b.trustpay.client.XMLDocument(builder.ToString());
}
}
}
}

+ 37
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrnxResult.cs View File

@ -0,0 +1,37 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class TrnxResult : TrxResponse
{
public TrnxResult init(string aMessage)
{
LogWriter writer = null;
try
{
writer = new LogWriter(MerchantConfig.getTrxLogFile("TrnxResultLog"));
writer.logNewLine("接收到的支付结果通知:\n[" + aMessage + "]");
Base64 base2 = new Base64();
string aXMLString = Encoding.GetEncoding("gb2312").GetString(base2.decode(aMessage));
writer.logNewLine("经过Base64解码后的支付结果通知:\n[" + aXMLString + "]");
writer.logNewLine("验证支付结果通知的签名:");
writer.logNewLine("验证通过!\n 经过验证的支付结果通知:\n[" + MerchantConfig.verifySign(new XMLDocument(aXMLString)).ToString() + "]");
base.init(new XMLDocument(aXMLString));
}
catch (TrxException exception)
{
this.setReturnCode(exception.Code);
this.setErrorMessage(exception.Message + "-" + exception.DetailMessage);
writer.log("验证失败!\n");
}
if (writer != null)
{
writer.closeWriter();
}
return this;
}
}
}

+ 20
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/TrxType.cs View File

@ -0,0 +1,20 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using System;
public class TrxType
{
public const string TRX_TYPE_DOWNLOAD_TRNX = "DownloadTrnx";
public const string TRX_TYPE_FREEZE = "Freeze";
public const string TRX_TYPE_FREEZE_RESULT = "FreezeResult";
public const string TRX_TYPE_FREEZE_TRANSFER = "FreezeTransfer";
public const string TRX_TYPE_FUND_TRANSFER = "FundTransfer";
public const string TRX_TYPE_PART_FREEZE_TRANSFER = "PartFreezeTransfer";
public const string TRX_TYPE_PART_UNFREEZE = "PartUnFreeze";
public const string TRX_TYPE_PAY_FEE = "PayFee";
public const string TRX_TYPE_QUERY_TRNX = "QueryTrnx";
public const string TRX_TYPE_UNFREEZE = "UnFreeze";
public const string TRX_TYPE_UNFREEZE_RESULT = "UnFreezeResult";
}
}

+ 397
- 0
B2B/TrustPay/com/hitrust/b2b/trustpay/client/b2b/UnFreezeRequest.cs View File

@ -0,0 +1,397 @@
namespace com.hitrust.b2b.trustpay.client.b2b
{
using com.hitrust.b2b.trustpay.client;
using System;
using System.Text;
public class UnFreezeRequest : TrxRequest
{
public const int ACCOUNT_BANK_URL_LEN = 50;
public const int ACCOUNT_NAME_URL_LEN = 50;
public const int ACCOUNT_NO_URL_LEN = 20;
public const int CORPOR_CUSTOMER_URL_LEN = 100;
private string iAccountBank;
private string iAccountName;
private string iAccountNo;
private string iCorporationCustomerNo;
private string iMerchantRemarks;
private string iMerchantTrnxNo;
private string iOrginalFreezeNo;
private string iOrginalTrnxSN;
private string iResultNotifyURL;
private double iTrnxAmount;
private string iTrnxDate;
private com.hitrust.b2b.trustpay.client.b2b.TrnxInfo iTrnxInfo;
private string iTrnxTime;
public const int MERCHANT_REMARKS_LEN = 200;
public const int MERCHANT_TRNX_URL_LEN = 20;
public const int ORGINAL_FREEZE_NO_URL_LEN = 6;
public const int ORGINAL_TRNX_SN_URL_LEN = 20;
public const int RESULT_NOTIFY_URL_LEN = 200;
public UnFreezeRequest() : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
}
public UnFreezeRequest(XMLDocument aXMLDocument) : base("B2B")
{
this.iTrnxInfo = null;
this.iCorporationCustomerNo = "";
this.iMerchantTrnxNo = "";
this.iTrnxDate = "";
this.iTrnxAmount = 0.0;
this.iTrnxTime = "";
this.iAccountNo = "";
this.iAccountName = "";
this.iAccountBank = "";
this.iOrginalTrnxSN = "";
this.iOrginalFreezeNo = "";
this.iResultNotifyURL = "";
this.iMerchantRemarks = "";
this.TrnxInfo = new com.hitrust.b2b.trustpay.client.b2b.TrnxInfo(aXMLDocument);
this.CorporationCustomerNo = aXMLDocument.getValueNoNull("CorporationCustomerNo");
this.MerchantTrnxNo = aXMLDocument.getValueNoNull("MerchantTrnxNo");
try
{
this.TrnxAmount = double.Parse(aXMLDocument.getValueNoNull("TrnxAmount"));
}
catch (Exception)
{
}
this.TrnxDate = aXMLDocument.getValueNoNull("TrnxDate");
this.TrnxTime = aXMLDocument.getValueNoNull("TrnxTime");
this.OrginalTrnxSN = aXMLDocument.getValueNoNull("OrginalTrnxSN");
this.OrginalFreezeNo = aXMLDocument.getValueNoNull("OrginalFreezeNo");
this.AccountNo = aXMLDocument.getValueNoNull("AccountNo");
this.AccountName = aXMLDocument.getValueNoNull("AccountName");
this.AccountBank = aXMLDocument.getValueNoNull("AccountBank");
this.ResultNotifyURL = aXMLDocument.getValueNoNull("ResultNotifyURL");
this.MerchantRemarks = aXMLDocument.getValueNoNull("MerchantRemarks");
}
protected internal override void checkRequest()
{
if (this.iTrnxInfo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易详细信息!");
}
if (this.iCorporationCustomerNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定企业客户代码!");
}
if (this.iMerchantTrnxNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定商户交易编号!");
}
if (this.iTrnxAmount <= 0.0)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易金额!");
}
if (this.iTrnxDate == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易日期!");
}
if (this.iTrnxTime == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易时间!");
}
if (this.iOrginalTrnxSN == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易流水号!");
}
if (this.iOrginalFreezeNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定原冻结序号!");
}
if (this.iAccountNo == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账号!");
}
if (this.iAccountName == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账户名!");
}
if (this.iAccountBank == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定账户开户行!");
}
if (this.iResultNotifyURL == null)
{
throw new TrxException("1100", "商户提交的交易资料不完整", "未设定交易结果回传网址!");
}
if (!this.iTrnxInfo.Valid)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易详细信息不合法!");
}
if (this.iCorporationCustomerNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iCorporationCustomerNo)).Length > 100)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "企业客户代码不合法!");
}
if (this.iMerchantTrnxNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantTrnxNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户交易编号不合法!");
}
if (this.iOrginalTrnxSN.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalTrnxSN)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易流水号不合法!");
}
if (this.iOrginalFreezeNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iOrginalFreezeNo)).Length > 6)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "原冻结序号不合法!");
}
if (this.iAccountNo.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账号不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountNo)).Length > 20)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账号不合法!");
}
if (this.iAccountName.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户名不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountName)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户名不合法!");
}
if (this.iAccountBank.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户开户行不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iAccountBank)).Length > 50)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "账户开户行不合法!");
}
if (!DataVerifier.isValidDate(this.iTrnxDate))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易日期不合法!");
}
if (!DataVerifier.isValidTime(this.iTrnxTime))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易时间不合法!");
}
if (!DataVerifier.isValidAmount(this.iTrnxAmount, 2))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易金额不合法!");
}
if (!DataVerifier.isValidURL(this.iResultNotifyURL))
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (this.iResultNotifyURL.Length == 0)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iResultNotifyURL)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "交易结果回传网址不合法!");
}
if (SupportClass.ToSByteArray(SupportClass.ToByteArray(this.iMerchantRemarks)).Length > 200)
{
throw new TrxException("1101", "商户提交的交易资料不合法", "商户备注信息不合法!");
}
}
protected internal override TrxResponse constructResponse(XMLDocument aResponseMessage)
{
return new TrxResponse(aResponseMessage);
}
public virtual string AccountBank
{
get
{
return this.iAccountBank;
}
set
{
this.iAccountBank = value.Trim();
}
}
public virtual string AccountName
{
get
{
return this.iAccountName;
}
set
{
this.iAccountName = value.Trim();
}
}
public virtual string AccountNo
{
get
{
return this.iAccountNo;
}
set
{
this.iAccountNo = value.Trim();
}
}
public virtual string CorporationCustomerNo
{
get
{
return this.iCorporationCustomerNo;
}
set
{
this.iCorporationCustomerNo = value.Trim();
}
}
public virtual string MerchantRemarks
{
get
{
return this.iMerchantRemarks;
}
set
{
this.iMerchantRemarks = value.Trim();
}
}
public virtual string MerchantTrnxNo
{
get
{
return this.iMerchantTrnxNo;
}
set
{
this.iMerchantTrnxNo = value.Trim();
}
}
public virtual string OrginalFreezeNo
{
get
{
return this.iOrginalFreezeNo;
}
set
{
this.iOrginalFreezeNo = value.Trim();
}
}
public virtual string OrginalTrnxSN
{
get
{
return this.iOrginalTrnxSN;
}
set
{
this.iOrginalTrnxSN = value.Trim();
}
}
protected internal override XMLDocument RequestMessage
{
get
{
StringBuilder builder = new StringBuilder();
builder.Append("<Corporation>").Append("<CorporationCustomerNo>" + this.iCorporationCustomerNo + "</CorporationCustomerNo>").Append("</Corporation>").Append("<TrxRequest>").Append("<TrxType>UnFreeze</TrxType>").Append("<MerchantTrnxNo>" + this.iMerchantTrnxNo + "</MerchantTrnxNo>").Append("<TrnxAmount>" + DataVerifier.Double2String(this.iTrnxAmount) + "</TrnxAmount>").Append("<TrnxDate>" + this.iTrnxDate + "</TrnxDate>").Append("<TrnxTime>" + this.iTrnxTime + "</TrnxTime>").Append("<OrginalTrnxSN>" + this.iOrginalTrnxSN + "</OrginalTrnxSN>").Append("<OrginalFreezeNo>" + this.iOrginalFreezeNo + "</OrginalFreezeNo>").Append("<Account>").Append("<AccountNo>" + this.iAccountNo + "</AccountNo>").Append("<AccountName>" + this.iAccountName + "</AccountName>").Append("<AccountBank>" + this.iAccountBank + "</AccountBank>").Append("</Account>").Append(this.iTrnxInfo.XMLDocument.ToString()).Append("<ResultNotifyURL>" + this.iResultNotifyURL + "</ResultNotifyURL>").Append("<MerchantRemarks>" + this.iMerchantRemarks + "</MerchantRemarks>").Append("</TrxRequest>");
return new XMLDocument(builder.ToString());
}
}
public virtual string ResultNotifyURL
{
get
{
return this.iResultNotifyURL;
}
set
{
this.iResultNotifyURL = value.Trim();
}
}
public virtual double TrnxAmount
{
get
{
return this.iTrnxAmount;
}
set
{
this.iTrnxAmount = value;
}
}
public virtual string TrnxDate
{
get
{
return this.iTrnxDate;
}
set
{
this.iTrnxDate = value.Trim();
}
}
public virtual com.hitrust.b2b.trustpay.client.b2b.TrnxInfo TrnxInfo
{
get
{
return this.iTrnxInfo;
}
set
{
this.iTrnxInfo = value;
}
}
public virtual string TrnxTime
{
get
{
return this.iTrnxTime;
}
set
{
this.iTrnxTime = value.Trim();
}
}
}
}

BIN
B2B/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache View File


+ 167
- 0
B2C/B2C.csproj View File

@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{605CA8A0-2034-4675-8D2C-64619C7F2AAB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bwp.ABCClient2.B2C</RootNamespace>
<AssemblyName>ABCClient2.B2C</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<KeyContainerName>BwpApp</KeyContainerName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Core">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Xml.Linq">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Microsoft.CSharp">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Data">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Xml">
<SpecificVersion>False</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\version\tslib_version.cs">
<Link>tslib_version.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CertificateContext.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CertificateExtension.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CertificateInfo.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CertificateNameInfo.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CertificateNameValue.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\AuthType.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\Certificate.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateChain.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateChainOptions.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateException.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateStatus.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateStore.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateStoreCollection.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateStoreType.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\CertificateVerificationResult.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\DistinguishedName.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\DistinguishedNameList.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\Extension.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\HashType.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\KeysetLocation.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\KeyUsage.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\NameAttribute.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\StoreLocation.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Certificates\VerificationFlags.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CERT_EXTENSION.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CERT_PUBLIC_KEY_INFO.cs" />
<Compile Include="TrustPay\com\hitrust\Security\ChainParameters.cs" />
<Compile Include="TrustPay\com\hitrust\Security\ChainPolicyParameters.cs" />
<Compile Include="TrustPay\com\hitrust\Security\ChainPolicyStatus.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\ARCFourManaged.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\ARCFourManagedTransform.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\CryptoAlgorithm.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\CryptoMethod.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\CryptoProvider.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\ProtectionType.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\PUBLICKEYSTRUC.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\RC4.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\RC4CryptoServiceProvider.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\RC4UnmanagedTransform.cs" />
<Compile Include="TrustPay\com\hitrust\Security\Cryptography\SymmetricKey.cs" />
<Compile Include="TrustPay\com\hitrust\Security\CRYPT_KEY_PROV_INFO.cs" />
<Compile Include="TrustPay\com\hitrust\Security\DataBlob.cs" />
<Compile Include="TrustPay\com\hitrust\Security\PROV_ENUMALGS_EX.cs" />
<Compile Include="TrustPay\com\hitrust\Security\PUBLIC_KEY_BLOB.cs" />
<Compile Include="TrustPay\com\hitrust\Security\RdnAttribute.cs" />
<Compile Include="TrustPay\com\hitrust\Security\RelativeDistinguishedName.cs" />
<Compile Include="TrustPay\com\hitrust\Security\SecurityConstants.cs" />
<Compile Include="TrustPay\com\hitrust\Security\SecurityException.cs" />
<Compile Include="TrustPay\com\hitrust\Security\SslPolicyParameters.cs" />
<Compile Include="TrustPay\com\hitrust\Security\SspiProvider.cs" />
<Compile Include="TrustPay\com\hitrust\Security\TrustListUsage.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\FundPaymentRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\Order.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\OrderItem.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\PaymentRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\PaymentResult.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\QueryOrderRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\RefundRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\SettleFile.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\SettleRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\TrxType.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\VoidPaymentRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\b2c\VoidRefundRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\Base64.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\DataVerifier.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\HiCalendar.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\IniFileParser.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\LogWriter.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\MerchantConfig.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\MyPolicy.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\TrxException.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\TrxRequest.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\TrxResponse.cs" />
<Compile Include="TrustPay\com\hitrust\trustpay\client\XMLDocument.cs" />
<Compile Include="TrustPay\com\hitrust\util\Checksums\Adler32.cs" />
<Compile Include="TrustPay\com\hitrust\util\Checksums\Crc32.cs" />
<Compile Include="TrustPay\com\hitrust\util\Checksums\IChecksum.cs" />
<Compile Include="TrustPay\com\hitrust\util\GZip\GZipConstants.cs" />
<Compile Include="TrustPay\com\hitrust\util\GZip\GZipException.cs" />
<Compile Include="TrustPay\com\hitrust\util\GZip\GZipInputStream.cs" />
<Compile Include="TrustPay\com\hitrust\util\SharpZipBaseException.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\Deflater.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\DeflaterConstants.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\DeflaterEngine.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\DeflaterHuffman.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\DeflaterPending.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\DeflateStrategy.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\Inflater.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\InflaterDynHeader.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\InflaterHuffmanTree.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\PendingBuffer.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\Streams\InflaterInputStream.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\Streams\OutputWindow.cs" />
<Compile Include="TrustPay\com\hitrust\util\Zip\Compression\Streams\StreamManipulator.cs" />
<Compile Include="TrustPay\SupportClass.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

+ 35
- 0
B2C/Properties/AssemblyInfo.cs View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("B2C")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("B2C")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("83eb7f08-d1b0-4671-b073-f5327ce1e0a5")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]

+ 216
- 0
B2C/TrustPay/SupportClass.cs View File

@ -0,0 +1,216 @@
using System;
using System.IO;
using System.Security.Cryptography;
public class SupportClass
{
public static int ReadInput(Stream sourceStream, ref sbyte[] target, int start, int count)
{
byte[] buffer = new byte[target.Length];
int num = sourceStream.Read(buffer, start, count);
for (int i = start; i < (start + num); i++) {
target[i] = (sbyte)buffer[i];
}
return num;
}
public static int ReadInput(TextReader sourceTextReader, ref sbyte[] target, int start, int count)
{
char[] buffer = new char[target.Length];
int num = sourceTextReader.Read(buffer, start, count);
for (int i = start; i < (start + num); i++) {
target[i] = (sbyte)buffer[i];
}
return num;
}
public static byte[] ToByteArray(string sourceString)
{
byte[] buffer = new byte[sourceString.Length];
for (int i = 0; i < sourceString.Length; i++) {
buffer[i] = (byte)sourceString[i];
}
return buffer;
}
public static byte[] ToByteArray(byte[] sbyteArray)
{
byte[] buffer = new byte[sbyteArray.Length];
for (int i = 0; i < sbyteArray.Length; i++) {
buffer[i] = sbyteArray[i];
}
return buffer;
}
public static char[] ToCharArray(byte[] byteArray)
{
char[] array = new char[byteArray.Length];
byteArray.CopyTo(array, 0);
return array;
}
public static char[] ToCharArray(sbyte[] sByteArray)
{
char[] array = new char[sByteArray.Length];
sByteArray.CopyTo(array, 0);
return array;
}
public static sbyte[] ToSByteArray(byte[] byteArray)
{
sbyte[] numArray = new sbyte[byteArray.Length];
for (int i = 0; i < byteArray.Length; i++) {
numArray[i] = (sbyte)byteArray[i];
}
return numArray;
}
public static void WriteStackTrace(Exception throwable, TextWriter stream)
{
stream.Write(throwable.StackTrace);
stream.Flush();
}
public class DigitalSignature
{
private string algorithmName;
private byte[] data;
private AsymmetricSignatureDeformatter deformatter;
private AsymmetricSignatureFormatter formatter;
private HashAlgorithm hashAlgorithm;
private int objective;
private int position;
protected DigitalSignature() {}
public static DigitalSignature GetInstance(string algorithmName)
{
if (!algorithmName.ToLower().Equals("sha1withdsa") && !algorithmName.ToLower().Equals("shawithdsa")) {
throw new Exception("Algorithm not supported");
}
return new DigitalSignature {
formatter = new DSASignatureFormatter(),
deformatter = new DSASignatureDeformatter(),
hashAlgorithm = new SHA1Managed(),
algorithmName = "SHAwithDSA",
objective = 0
};
}
private void Reset()
{
this.data = null;
this.position = 0;
}
public byte[] Sign()
{
byte[] buffer = null;
if (this.objective != 1) {
throw new Exception("Object was not created for signing");
}
buffer = this.formatter.CreateSignature(this.Data);
this.Reset();
return buffer;
}
public void Signing()
{
this.objective = 1;
}
public override string ToString()
{
string str = "Instance of DigitalSignature for ";
if (this.objective == 1) {
str = str + "signing ";
} else {
str = str + "verification ";
}
return (str + "using " + this.AlgorithmName + " algorithm");
}
public void Update(byte[] newData)
{
if (this.position == 0) {
this.Data = newData;
this.hashAlgorithm.TransformBlock(newData, 0, newData.Length, this.Data, 0);
this.position = this.Data.Length - 1;
} else {
byte[] data = this.Data;
this.Data = new byte[(newData.Length + this.position) + 1];
data.CopyTo(this.Data, 0);
byte[] outputBuffer = newData;
this.hashAlgorithm.TransformBlock(newData, 0, outputBuffer.Length, outputBuffer, 0);
outputBuffer.CopyTo(this.Data, data.Length);
this.position = this.Data.Length - 1;
}
}
public void Update(byte newData)
{
byte[] buffer = new byte[] {newData};
this.Update(buffer);
}
public void Update(byte[] newData, int offset, int count)
{
byte[] destinationArray = new byte[count];
Array.Copy(newData, offset, destinationArray, 0, count);
this.Update(destinationArray);
}
public void Verification()
{
this.objective = 2;
}
public bool Verify(byte[] signature)
{
bool flag = false;
if (this.objective != 2) {
throw new Exception("Object was not created for verification");
}
flag = this.deformatter.VerifySignature(this.Data, signature);
this.Reset();
return flag;
}
public string AlgorithmName
{
get { return this.algorithmName; }
}
public byte[] Data
{
get { return this.data; }
set { this.data = value; }
}
}
public class KeySupport
{
private readonly KeyedHashAlgorithm algorithm;
public KeySupport() {}
public KeySupport(KeyedHashAlgorithm algorithm)
{
this.algorithm = algorithm;
}
public string GetAlgorithm()
{
return this.algorithm.ToString();
}
public byte[] Key
{
get { return this.algorithm.Key; }
}
}
public class PrivateKeySupport : KeySupport {}
public class PublicKeySupport : KeySupport {}
}

+ 15
- 0
B2C/TrustPay/com/hitrust/Security/CERT_EXTENSION.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CERT_EXTENSION
{
public IntPtr pszObjId;
public int fCritical;
public int ValuecbData;
public IntPtr ValuepbData;
}
}

+ 26
- 0
B2C/TrustPay/com/hitrust/Security/CERT_PUBLIC_KEY_INFO.cs View File

@ -0,0 +1,26 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CERT_PUBLIC_KEY_INFO
{
public IntPtr pszObjId;
public int agcbData;
public IntPtr agpbData;
public int pkcbData;
public IntPtr pkpbData;
public int pkcUnusedBits;
public CERT_PUBLIC_KEY_INFO(CertificateInfo info)
{
this.pszObjId = info.SubjectPublicKeyInfoAlgorithmpszObjId;
this.agcbData = info.SubjectPublicKeyInfoAlgorithmParameterscbData;
this.agpbData = info.SubjectPublicKeyInfoAlgorithmParameterspbData;
this.pkcbData = info.SubjectPublicKeyInfoPublicKeycbData;
this.pkpbData = info.SubjectPublicKeyInfoPublicKeypbData;
this.pkcUnusedBits = info.SubjectPublicKeyInfoPublicKeycUnusedBits;
}
}
}

+ 20
- 0
B2C/TrustPay/com/hitrust/Security/CRYPT_KEY_PROV_INFO.cs View File

@ -0,0 +1,20 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
internal struct CRYPT_KEY_PROV_INFO
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pwszContainerName;
[MarshalAs(UnmanagedType.LPWStr)]
public string pwszProvName;
public int dwProvType;
public int dwFlags;
public int cProvParam;
public IntPtr rgProvParam;
public int dwKeySpec;
}
}

+ 16
- 0
B2C/TrustPay/com/hitrust/Security/CertificateContext.cs View File

@ -0,0 +1,16 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateContext
{
public int dwCertEncodingType;
public IntPtr pbCertEncoded;
public int cbCertEncoded;
public IntPtr pCertInfo;
public IntPtr hCertStore;
}
}

+ 15
- 0
B2C/TrustPay/com/hitrust/Security/CertificateExtension.cs View File

@ -0,0 +1,15 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateExtension
{
public IntPtr pszObjId;
public int fCritical;
public int cbData;
public IntPtr pbData;
}
}

+ 37
- 0
B2C/TrustPay/com/hitrust/Security/CertificateInfo.cs View File

@ -0,0 +1,37 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateInfo
{
public int dwVersion;
public int SerialNumbercbData;
public IntPtr SerialNumberpbData;
public IntPtr SignatureAlgorithmpszObjId;
public int SignatureAlgorithmParameterscbData;
public IntPtr SignatureAlgorithmParameterspbData;
public int IssuercbData;
public IntPtr IssuerpbData;
public long NotBefore;
public long NotAfter;
public int SubjectcbData;
public IntPtr SubjectpbData;
public IntPtr SubjectPublicKeyInfoAlgorithmpszObjId;
public int SubjectPublicKeyInfoAlgorithmParameterscbData;
public IntPtr SubjectPublicKeyInfoAlgorithmParameterspbData;
public int SubjectPublicKeyInfoPublicKeycbData;
public IntPtr SubjectPublicKeyInfoPublicKeypbData;
public int SubjectPublicKeyInfoPublicKeycUnusedBits;
public int IssuerUniqueIdcbData;
public IntPtr IssuerUniqueIdpbData;
public int IssuerUniqueIdcUnusedBits;
public int SubjectUniqueIdcbData;
public IntPtr SubjectUniqueIdpbData;
public int SubjectUniqueIdcUnusedBits;
public int cExtension;
public IntPtr rgExtension;
}
}

+ 13
- 0
B2C/TrustPay/com/hitrust/Security/CertificateNameInfo.cs View File

@ -0,0 +1,13 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateNameInfo
{
public int cRDN;
public IntPtr rgRDN;
}
}

+ 14
- 0
B2C/TrustPay/com/hitrust/Security/CertificateNameValue.cs View File

@ -0,0 +1,14 @@
namespace com.hitrust.Security
{
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
internal struct CertificateNameValue
{
public int dwValueType;
public int cbData;
public IntPtr pbData;
}
}

+ 11
- 0
B2C/TrustPay/com/hitrust/Security/Certificates/AuthType.cs View File

@ -0,0 +1,11 @@
namespace com.hitrust.Security.Certificates
{
using System;
public enum AuthType
{
Client = 1,
Server = 2
}
}

+ 1032
- 0
B2C/TrustPay/com/hitrust/Security/Certificates/Certificate.cs
File diff suppressed because it is too large
View File


+ 239
- 0
B2C/TrustPay/com/hitrust/Security/Certificates/CertificateChain.cs View File

@ -0,0 +1,239 @@
namespace com.hitrust.Security.Certificates
{
using com.hitrust.Security;
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
public class CertificateChain
{
private com.hitrust.Security.Certificates.Certificate m_Certificate;
private IntPtr m_Handle;
public CertificateChain(com.hitrust.Security.Certificates.Certificate cert) : this(cert, null)
{
}
public CertificateChain(com.hitrust.Security.Certificates.Certificate cert, CertificateStore additional) : this(cert, additional, CertificateChainOptions.Default)
{
}
public CertificateChain(com.hitrust.Security.Certificates.Certificate cert, CertificateStore additional, CertificateChainOptions options)
{
if (cert == null)
{
throw new ArgumentNullException();
}
IntPtr hAdditionalStore = (additional == null) ? IntPtr.Zero : additional.Handle;
ChainParameters pChainPara = new ChainParameters {
cbSize = Marshal.SizeOf(typeof(ChainParameters)),
RequestedUsagecUsageIdentifier = 0,
RequestedUsagedwType = 0,
RequestedUsagergpszUsageIdentifier = IntPtr.Zero
};
if (SspiProvider.CertGetCertificateChain(IntPtr.Zero, cert.Handle, IntPtr.Zero, hAdditionalStore, ref pChainPara, (int) options, IntPtr.Zero, ref this.m_Handle) == 0)
{
throw new CertificateException("Unable to find the certificate chain.");
}
this.m_Certificate = cert;
}
public virtual IAsyncResult BeginVerifyChain(string server, AuthType type, VerificationFlags flags, AsyncCallback callback, object asyncState)
{
CertificateVerificationResult state = new CertificateVerificationResult(this, server, type, flags, callback, asyncState);
if (!ThreadPool.QueueUserWorkItem(new WaitCallback(this.StartVerification), state))
{
throw new CertificateException("Could not schedule the certificate chain for verification.");
}
return state;
}
public virtual CertificateStatus EndVerifyChain(IAsyncResult ar)
{
CertificateVerificationResult result;
if (ar == null)
{
throw new ArgumentNullException();
}
try
{
result = (CertificateVerificationResult) ar;
}
catch
{
throw new ArgumentException();
}
if (result.Chain != this)
{
throw new ArgumentException();
}
if (result.HasEnded)
{
throw new InvalidOperationException();
}
if (result.ThrowException != null)
{
throw result.ThrowException;
}
result.HasEnded = true;
return result.Status;
}
~CertificateChain()
{
if (this.m_Handle != IntPtr.Zero)
{
SspiProvider.CertFreeCertificateChain(this.m_Handle);
this.m_Handle = IntPtr.Zero;
}
}
public virtual com.hitrust.Security.Certificates.Certificate[] GetCertificates()
{
ArrayList list = new ArrayList();
IntPtr handle = ((com.hitrust.Security.Certificates.Certificate) this.Certificate.Clone()).Handle;
CertificateStoreCollection store = this.Certificate.Store as CertificateStoreCollection;
if (store != null)
{
store = new CertificateStoreCollection(store);
}
else
{
store = new CertificateStoreCollection(new CertificateStore[0]);
store.AddStore(new CertificateStore(this.Certificate.m_Context.hCertStore, true));
}
store.AddStore(new CertificateStore("Root"));
IntPtr hCertStore = store.Handle;
while (handle != IntPtr.Zero)
{
list.Add(new com.hitrust.Security.Certificates.Certificate(handle, true));
int pdwFlags = 0;
handle = SspiProvider.CertGetIssuerCertificateFromStore(hCertStore, handle, IntPtr.Zero, ref pdwFlags);
}
return (com.hitrust.Security.Certificates.Certificate[]) list.ToArray(typeof(com.hitrust.Security.Certificates.Certificate));
}
protected void StartVerification(object state)
{
if (state != null)
{
CertificateVerificationResult result;
CertificateStatus status;
try
{
result = (CertificateVerificationResult) state;
}
catch
{
return;
}
try
{
status = this.VerifyChain(result.Server, result.Type, result.Flags);
}
catch (CertificateException exception)
{
result.VerificationCompleted(exception, CertificateStatus.OtherError);
return;
}
catch (Exception exception2)
{
result.VerificationCompleted(new CertificateException("Could not verify the certificate chain.", exception2), CertificateStatus.OtherError);
return;
}
result.VerificationCompleted(null, status);
}
}
public virtual CertificateStatus VerifyChain(string server, AuthType type)
{
return this.VerifyChain(server, type, VerificationFlags.None);
}
public virtual CertificateStatus VerifyChain(string server, AuthType type, VerificationFlags flags)
{
CertificateStatus otherError;
IntPtr zero = IntPtr.Zero;
IntPtr ptr = IntPtr.Zero;
try
{
if (server == null)
{
zero = IntPtr.Zero;
}
else
{
zero = Marshal.StringToHGlobalUni(server);
}
SslPolicyParameters structure = new SslPolicyParameters {
cbSize = Marshal.SizeOf(typeof(SslPolicyParameters)),
dwAuthType = (int) type,
pwszServerName = zero,
fdwChecks = (int) flags
};
ptr = Marshal.AllocHGlobal(structure.cbSize);
Marshal.StructureToPtr(structure, ptr, false);
ChainPolicyParameters pPolicyPara = new ChainPolicyParameters {
cbSize = Marshal.SizeOf(typeof(ChainPolicyParameters)),
dwFlags = (int) flags,
pvExtraPolicyPara = ptr
};
ChainPolicyStatus pPolicyStatus = new ChainPolicyStatus {
cbSize = Marshal.SizeOf(typeof(ChainPolicyStatus))
};
if (SspiProvider.CertVerifyCertificateChainPolicy(new IntPtr(4), this.m_Handle, ref pPolicyPara, ref pPolicyStatus) == 0)
{
throw new CertificateException("Unable to verify the certificate.");
}
if (Enum.IsDefined(typeof(CertificateStatus), pPolicyStatus.dwError))
{
return (CertificateStatus) pPolicyStatus.dwError;
}
otherError = CertificateStatus.OtherError;
}
finally
{
if (ptr != IntPtr.Zero)
{
Marshal.FreeHGlobal(ptr);
}
if (zero != IntPtr.Zero)
{
Marshal.FreeHGlobal(zero);
}
}
return otherError;
}
public virtual CertificateStatus VerifyChain(string server, AuthType type, VerificationFlags flags, byte[] crl)
{
CertificateStatus status = this.VerifyChain(server, type, flags);
if ((status != CertificateStatus.ValidCertificate) || (crl == null))
{
return status;
}
try
{
if (!this.m_Certificate.VerifyRevocation(crl))
{
return CertificateStatus.Revoked;
}
return status;
}
catch
{
return CertificateStatus.RevocationFailure;
}
}
protected com.hitrust.Security.Certificates.Certificate Certificate
{
get
{
return this.m_Certificate;
}
}
}
}

+ 19
- 0
B2C/TrustPay/com/hitrust/Security/Certificates/CertificateChainOptions.cs View File

@ -0,0 +1,19 @@
namespace com.hitrust.Security.Certificates
{
using System;
public enum CertificateChainOptions
{
CacheOnlyUrlRetrieval = 4,
Default = 0,
DisableAuthRootAutoUpdate = 0x100,
DisablePass1QualityFiltering = 0x40,
ReturnLowerQualityContexts = 0x80,
RevocationCacheEndCert = 1,
RevocationCheckCacheOnly = -2147483648,
RevocationCheckChain = 0x20000000,
RevocationCheckChainExcludeRoot = 0x40000000,
RevocationCheckEndCert = 0x10000000
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save