Security and Data Integrity

This feature secures conversion data by providing AES encryption, key rotation, signature generation, and data integrity validation.

Overview

The Security & Data Integrity feature is designed to protect sensitive conversion data. It offers properties and methods to enable AES-256 encryption, rotate encryption keys securely, generate digital signatures, and validate the integrity of the data. This ensures that the numeric value and its word representation remain secure and unaltered during storage or transmission.


Key Points

Key Point
Description

AES Encryption

The UseAESEncryption property enables AES-256 encryption for the conversion data when activated.

Encryption key rotation

The RotateEncryptionKeys method securely replaces the encryption keys and optionally notifies subscribers of the change.

Encrypted value retrieval

The GetEncryptedValue method returns an encrypted representation of the current value and its corresponding words.

Signed encrypted output

The GetSignedEncryptedValue method provides both the encrypted data and a cryptographic signature for enhanced security.

Data integrity validation

The ValidateIntegrity method compares the current data hash with an expected hash to ensure data integrity.


Best Practices

Best Practice
Description

Enable encryption only when necessary

Use the UseAESEncryption property to activate encryption only when handling sensitive data to optimize performance.

Regularly rotate encryption keys

Call RotateEncryptionKeys periodically to maintain a high level of security, and subscribe to OnEncryptionKeyRotated for monitoring key changes.

Validate data integrity before processing

Use ValidateIntegrity to verify that the conversion data has not been tampered with prior to further processing.

Handle exceptions gracefully

Catch exceptions from encryption methods (e.g., if encryption is disabled) and provide informative error messages to users.


Common Pitfalls

Pitfall
Description

Using encryption methods without enabling encryption

Attempting to call GetSignedEncryptedValue when UseAESEncryption is false can lead to exceptions or unexpected behavior.

Failing to handle key rotation notifications

Not subscribing to the OnEncryptionKeyRotated event might lead to missing important updates regarding key changes.

Overlooking secure disposal of keys

Not disposing or clearing encryption keys and sensitive data during disposal can leave the application vulnerable to data leaks.

Ignoring the salt mechanism

Failing to understand the role of salt in encryption might result in less secure encryption if the salt is mishandled.


Usage Scenarios

Scenario
Description

Securing sensitive numeric conversions

Enable encryption to protect the numeric value and word conversion when transmitting data over insecure networks.

Periodic security maintenance

Regularly call RotateEncryptionKeys to update encryption keys and maintain robust security in long-running applications.

Integrity checking in data pipelines

Use ValidateIntegrity to ensure that conversion data has not been altered during storage or transmission in distributed systems.


Real Life Usage Scenarios

Scenario
Description

Financial applications

Encrypting transaction amounts and their textual representations before storage or transmission to meet regulatory requirements.

Healthcare systems

Protecting sensitive patient information when converting and transmitting numerical data such as billing or dosage information.

Enterprise data security

Securing logs or audit trails that include both numeric and textual data representations, ensuring data integrity and confidentiality.


Troubleshooting Tips

Issue
Possible Cause
Recommended Action

Exception when calling GetSignedEncryptedValue

Encryption may be disabled (UseAESEncryption is false).

Ensure that UseAESEncryption is set to true before calling the method.

Unexpected integrity validation failures

The computed hash does not match the expected value, possibly due to data alteration or a misconfigured conversion process.

Verify that the numeric value and its word representation are correct and have not been modified.

Missing key rotation notifications

The OnEncryptionKeyRotated event is not subscribed to or the notification logic is not implemented.

Subscribe to OnEncryptionKeyRotated and log or handle key rotation events appropriately.


Code Examples

Example 1: Enabling AES Encryption and Retrieving Encrypted Data

using SiticoneNetFrameworkUI;

// Create an instance of the control
var humanizer = new SiticoneHumanizerLong();

// Enable AES-256 encryption for sensitive data
humanizer.UseAESEncryption = true;

// Set a numeric value to convert
humanizer.Value = 2025;

// Retrieve the encrypted value
string encryptedValue = humanizer.GetEncryptedValue();
Console.WriteLine("Encrypted Value: " + encryptedValue);

Example 2: Retrieving Signed Encrypted Data

using SiticoneNetFrameworkUI;

// Create an instance of the control and enable encryption
var humanizer = new SiticoneHumanizerLong { UseAESEncryption = true };
humanizer.Value = 3456;

try
{
    // Retrieve both the encrypted value and its digital signature
    var result = humanizer.GetSignedEncryptedValue();
    Console.WriteLine("Encrypted Value: " + result.EncryptedValue);
    Console.WriteLine("Signature: " + result.Signature);
}
catch (InvalidOperationException ex)
{
    Console.WriteLine("Error: " + ex.Message);
}

Example 3: Rotating Encryption Keys and Handling the Notification Event

using System;
using SiticoneNetFrameworkUI;

public class EncryptionDemo
{
    public static void Main()
    {
        var humanizer = new SiticoneHumanizerLong { UseAESEncryption = true };

        // Subscribe to key rotation event
        humanizer.OnEncryptionKeyRotated += (sender, e) =>
        {
            Console.WriteLine($"Encryption key rotated at {e.RotationTimestamp}. New key hash: {e.KeyHash}");
        };

        // Rotate the encryption keys
        humanizer.RotateEncryptionKeys();
    }
}

Example 4: Validating Data Integrity

using SiticoneNetFrameworkUI;

// Create an instance of the control and set a numeric value
var humanizer = new SiticoneHumanizerLong { UseAESEncryption = true };
humanizer.Value = 7890;

// Obtain an integrity hash (internally computed using SHA512)
string currentHash = humanizer.GetEncryptedValue(); // For demonstration, using encrypted value

// Later, validate the integrity by comparing with an expected hash
bool isValid = humanizer.ValidateIntegrity(currentHash);
Console.WriteLine("Data integrity valid: " + isValid);

Review

Aspect
Review Comments

Security implementation

The feature uses robust AES-256 encryption and includes key rotation and signature methods to secure sensitive conversion data.

Ease of integration

Security methods integrate seamlessly with the core conversion process, offering straightforward API calls for encryption and validation.

Data integrity assurance

The ability to validate data integrity helps prevent data tampering, ensuring the reliability of conversion outputs.


Summary

Summary Statement
Description

Security & Data Integrity secures conversion data using AES encryption, key rotation, and integrity validation

This feature protects sensitive numeric and textual data by providing robust encryption mechanisms, digital signatures, and hash-based integrity checks, ensuring that the conversion data remains confidential and unaltered.


Additional Useful Sections

Integration Checklist

Checklist Item
Status/Notes

Enable AES encryption

Set the UseAESEncryption property to true if the conversion data is sensitive.

Regularly rotate keys

Schedule calls to RotateEncryptionKeys and subscribe to OnEncryptionKeyRotated to monitor key changes.

Validate data integrity

Use the ValidateIntegrity method to ensure data has not been tampered with before further processing or storage.

Securely dispose sensitive data

Ensure that the control is properly disposed to clear encryption keys and sensitive data.

FAQ

Question
Answer

How do I enable encryption for the conversion data?

Set the UseAESEncryption property to true to activate AES-256 encryption.

What happens if I try to retrieve a signed encrypted value when encryption is disabled?

An InvalidOperationException is thrown; ensure that encryption is enabled before calling GetSignedEncryptedValue.

How can I verify that my data has not been tampered with?

Use the ValidateIntegrity method to compare the current data hash with an expected hash value.

How do I know when encryption keys have been rotated?

Subscribe to the OnEncryptionKeyRotated event to receive notifications along with the rotation timestamp and key hash.


This comprehensive documentation for the Security & Data Integrity feature provides detailed guidance for developers to integrate, secure, and verify the conversion data in their .NET WinForms applications.

Last updated