CoralPay 1.9.1
dotnet add package CoralPay --version 1.9.1
NuGet\Install-Package CoralPay -Version 1.9.1
<PackageReference Include="CoralPay" Version="1.9.1" />
<PackageVersion Include="CoralPay" Version="1.9.1" />
<PackageReference Include="CoralPay" />
paket add CoralPay --version 1.9.1
#r "nuget: CoralPay, 1.9.1"
#addin nuget:?package=CoralPay&version=1.9.1
#tool nuget:?package=CoralPay&version=1.9.1
CoralPay Utility Library The CoralPay Utility Library is a comprehensive suite of tools designed to simplify common tasks for .NET applications, including string manipulation, HTTP request handling, and cryptographic operations. These utilities streamline the generation and manipulation of strings, as well as provide secure hashing and encryption methods, making it easier for developers to implement essential features such as secure data transmission, unique identifier creation, and effective string management in their applications.
Installation To use CoralPay Utility Library, you can include this library in your .NET project. by installing it via the NuGet Package Manager or the .NET CLI.
dotnet add package CoralPay CoralPay.StringHandler A utility library for working with strings, providing methods for generating unique identifiers, masking sensitive data like phone numbers, and manipulating strings in various ways.
Features Generate Unique Transaction ID: Creates a unique transaction ID based on the current time and random numbers.
Generate Unique Alphanumeric Text: Generates a unique string containing uppercase letters and numbers.
Generate Unique Text: Generates a string of random characters that includes special characters, numbers, and letters.
Reverse Text: Reverses the characters of a given string.
Unique Number: Generates a unique 20-character number using the current timestamp and random digits.
Mask Mobile Number: Masks part of a mobile number for privacy, returning a phone number in a masked format.
Methods GetTransactionId() Generates a unique transaction ID by combining the current date, time, and random numbers.
string transactionId = Stringer.GetTransactionId();
UniqueAlphaNumericText(int Length) Generates a unique alphanumeric text of the specified length.
string uniqueAlphaNumeric = Stringer.UniqueAlphaNumericText(10);
GetUniqueText(int Length) Generates a unique text string of the specified length. The string will contain a combination of letters and special characters.
string uniqueText = Stringer.GetUniqueText(15);
ReverseText(string Text) Reverses the given string.
string reversed = Stringer.ReverseText("Hello World");
UniqueNumber() Generates a unique 20-character number string based on the current date and time.
string uniqueNumber = Stringer.UniqueNumber();
MaskMobileNumber(string MobileNumber) Masks part of the given phone number to ensure privacy. The number is returned in a masked format with *** replacing part of the number.
string maskedPhone = Stringer.MaskMobileNumber("08123456789");
Usage Example Here’s an example of using some of the methods from the Stringer class:
using CoralPay.StringHandler;
class Program { static void Main(string[] args) { string transactionId = Stringer.GetTransactionId(); string uniqueAlphaNumeric = Stringer.UniqueAlphaNumericText(10); string reversedText = Stringer.ReverseText("Hello World"); string maskedPhone = Stringer.MaskMobileNumber("08123456789"); Console.WriteLine("Transaction ID: " + transactionId); Console.WriteLine("Unique Alphanumeric: " + uniqueAlphaNumeric); Console.WriteLine("Reversed Text: " + reversedText); Console.WriteLine("Masked Phone: " + maskedPhone); } } Dependencies This library has no external dependencies.
License This project is open-source and available under the MIT License.
HttpHandler - A Simple HTTP Service Client HttpHandler is a simple .NET library that facilitates making HTTP requests, serializing request/response data into various formats (JSON, XML, Plain Text), and handling different HTTP methods (GET, POST, PUT, DELETE). This library is designed to support both synchronous and asynchronous HTTP requests, making it easier for developers to integrate API calls into their applications.
Features Supports multiple content types:
JSON (application/json)
XML (application/xml, text/xml)
Plain text (text/plain)
Automatic serialization and deserialization:
Automatically serializes the request object into JSON, XML, or Plain Text based on the specified content type.
Deserializes responses back into objects in the specified content type.
Basic Authentication:
Easily add Basic Authentication headers to the HTTP request. Timeout Configuration:
Set custom timeouts for HTTP requests. Custom HTTP Headers:
Add custom HTTP headers for each request. SSL/TLS override:
Optionally override SSL certificate validation for scenarios where SSL verification is not required. Usage Below is a basic example demonstrating how to use the HttpService class to make an HTTP request.
Example:
using CoralPay.HttpHandler; using CoralPay.HttpHandler.Models; using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks;
class Program { static async Task Main(string[] args) { var request = new HttpServiceRequest<MyRequestObject> { Url = "https://api.example.com/endpoint", Method = HttpVerb.Get, ContentType = ContentType.ApplJson, RequestObject = new MyRequestObject { Property1 = "value1", Property2 = "value2" }, BasicAuth = new BasicAuth { Username = "username", Password = "password" }, Timeout = 30 // Set the timeout to 30 seconds };
var response = await HttpService.InvokeAsync<MyRequestObject, MyResponseObject>(request);
if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
{
Console.WriteLine($"Response: {response.ResponseObject.Property}");
}
else
{
Console.WriteLine($"Error: {response.ResponseMessage}");
}
}
}
public class MyRequestObject { public string Property1 { get; set; } public string Property2 { get; set; } }
public class MyResponseObject { public string Property { get; set; } } Explanation: Creating the Request:
Url: The URL to send the request to.
Method: HTTP method (GET, POST, PUT, DELETE).
ContentType: Specifies the content type (e.g., JSON, XML).
RequestObject: The object to be serialized into the request body.
BasicAuth: Optional Basic Authentication (Username and Password).
Timeout: The timeout in seconds for the request.
Calling InvokeAsync:
The InvokeAsync method is called with the HttpServiceRequest and will return a response that contains the deserialized response object and HTTP status code. Response Handling:
The response is checked for success (HTTP status OK) and the result is printed. Methods HttpService.InvokeAsync<TClientRequest, TClientResponse>(HttpServiceRequest<TClientRequest> request) This asynchronous method sends the HTTP request and returns an HttpServiceResponse<TClientResponse> containing the deserialized response.
Parameters: TClientRequest: Type of the request object.
TClientResponse: Type of the response object.
request: An HttpServiceRequest<TClientRequest> that contains the request details.
Returns: An HttpServiceResponse<TClientResponse> containing: ResponseObject: The deserialized response object.
HttpStatusCode: The HTTP status code of the response.
ResponseMessage: The reason phrase for the response.
ResponseString: The raw response string.
HttpService.Serialize(ContentType contentType, object request) This method serializes the request object into a string based on the specified content type.
Parameters: contentType: The content type to serialize the object into (e.g., application/json, application/xml).
request: The object to serialize.
Returns: A string representation of the serialized object. HttpService.GetMediaType(ContentType contentType) This method maps the content type enum to the appropriate media type string.
Parameters: contentType: The content type to map. Returns: The corresponding media type as a string (e.g., application/json, application/xml). HttpServiceRequest This class holds the details of the HTTP request.
Properties: Url: The URL to send the request to.
Method: The HTTP method to use (HttpVerb.Get, HttpVerb.Post, HttpVerb.Put, HttpVerb.Delete).
ContentType: The content type of the request (e.g., JSON, XML).
RequestObject: The object to be serialized and sent as the request body.
BasicAuth: Basic Authentication credentials (optional).
Timeout: Timeout in seconds for the HTTP request.
HttpHeaders: A dictionary of additional HTTP headers to send with the request.
SslOveride: Whether to override SSL certificate validation (optional).
HttpServiceResponse This class holds the response from the HTTP service.
Properties: ResponseObject: The deserialized response object.
HttpStatusCode: The HTTP status code of the response.
ResponseMessage: The reason phrase for the response.
ResponseString: The raw response string.
Content Types The following content types are supported for both requests and responses:
ApplJson: application/json
ApplXml: application/xml
TextXml: text/xml
TextPlain: text/plain
HTTP Methods (HttpVerb Enum) Get: HTTP GET method.
Post: HTTP POST method.
Put: HTTP PUT method.
Delete: HTTP DELETE method.
Error Handling Errors are handled gracefully, and the response will contain the appropriate HTTP status code and message in case of an error. Timeout errors will return GatewayTimeout.
Here is a README for the CoralPay.Cryptography library, including information on the PGP encryption and decryption functionality:
CoralPay Cryptography Library Overview The CoralPay Cryptography Library provides secure encryption and decryption utilities using the PGP (Pretty Good Privacy) standard. It includes methods for encrypting and decrypting data either from file paths or streams, offering flexibility in handling secure communications. This library supports both public key encryption and private key decryption operations and provides detailed responses for both success and error scenarios.
Key Features Encryption: Encrypts data using a public key, either from a file path or stream.
Decryption: Decrypts encrypted data using a private key, either from a file path or stream.
Error Handling: Clear response codes and messages to handle encryption or decryption failures.
Classes and Methods Pgp Class The Pgp class contains methods for encryption and decryption operations.
Methods
- Encrypt(FilePathBasedEncryptionRequest request) Encrypts plain text data using a public key from a file path.
Parameters:
request.PlainTextToEncrypt: The data to be encrypted.
request.PublicKeyFilePath: The file path to the public key.
Returns:
EncryptionResponse: Contains the encrypted data and a response header with a code and message. 2. Encrypt(StreamBasedEncryptionRequest request) Encrypts plain text data using a public key from a stream.
Parameters:
request.PlainTextToEncrypt: The data to be encrypted.
request.PublicKeyStream: The stream of the public key.
Returns:
EncryptionResponse: Contains the encrypted data and a response header with a code and message. 3. Decrypt(StreamBasedDecryptionRequest request) Decrypts encrypted data using a private key from a stream.
Parameters:
request.EncryptedText: The encrypted data to decrypt.
request.PrivateKeyStream: The stream of the private key.
request.PassPhrase: The passphrase for the private key.
Returns:
DecryptionResponse: Contains the decrypted data and a response header with a code and message. 4. Decrypt(FilePathBasedDecryptionRequest request) Decrypts encrypted data using a private key from a file path.
Parameters:
request.EncryptedText: The encrypted data to decrypt.
request.PrivateKeyFilePath: The file path to the private key.
request.PassPhrase: The passphrase for the private key.
Returns:
DecryptionResponse: Contains the decrypted data and a response header with a code and message. Data Models EncryptionResponse Encryption: The encrypted text.
ResponseHeader: Contains the response code ("00" for success, "01" for failure) and the response message.
DecryptionResponse Decryption: The decrypted text.
ResponseHeader: Contains the response code ("00" for success, "01" for failure) and the response message.
ResponseHeader ResponseCode: Status code indicating success or failure.
ResponseMessage: Descriptive message for the operation.
Example Usage Encrypting Data Using a File Path:
var encryptionRequest = new FilePathBasedEncryptionRequest { PlainTextToEncrypt = "SensitiveData", PublicKeyFilePath = @"C:\path\to\public_key.txt" };
var encryptionResponse = Pgp.Encrypt(encryptionRequest); Console.WriteLine(encryptionResponse.ResponseHeader.ResponseMessage); Decrypting Data Using a File Path:
var decryptionRequest = new FilePathBasedDecryptionRequest { EncryptedText = "EncryptedData", PrivateKeyFilePath = @"C:\path\to\private_key.txt", PassPhrase = "yourPassphrase" };
var decryptionResponse = Pgp.Decrypt(decryptionRequest); Console.WriteLine(decryptionResponse.Decryption); Error Handling ResponseCode "00": Operation successful.
ResponseCode "01": Operation failed.
Dependencies .NET Framework 5.0 or higher.
The library assumes the availability of a valid PGP key pair for encryption and decryption operations.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net9.0
- Portable.BouncyCastle (>= 1.9.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CoralPay:
Package | Downloads |
---|---|
TokenVault
For Internal use only |
GitHub repositories
This package is not used by any popular GitHub repositories.