feat(EnvelopeReceiverReadOnly): Erweiterungsmethode zum Kodieren und Dekodieren von Envelope-Receiver ReadOnly Id hinzugefügt

This commit is contained in:
Developer 02
2024-10-01 15:26:06 +02:00
parent 370666cb0e
commit 54e86b421c
2 changed files with 45 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using System.Security.Cryptography;
using System.Text;
namespace EnvelopeGenerator.Application
@@ -88,6 +89,22 @@ namespace EnvelopeGenerator.Application
return (string.Empty, string.Empty);
}
public static long? DecodeEnvelopeReceiverReadOnlyId(this string envelopeReceiverReadOnlyId)
{
if (!envelopeReceiverReadOnlyId.IsBase64String())
{
return null;
}
byte[] bytes = Convert.FromBase64String(envelopeReceiverReadOnlyId);
string decodedString = System.Text.Encoding.UTF8.GetString(bytes);
string[] parts = decodedString.Split(new string[] { "::" }, StringSplitOptions.None);
if (parts.Length > 2)
return long.TryParse(parts[1], out long readOnlyId) ? readOnlyId : null;
else
return null;
}
/// <summary>
/// Gets the envelope UUID from the decoded envelope receiver ID.
/// </summary>
@@ -111,7 +128,16 @@ namespace EnvelopeGenerator.Application
return base64String;
}
public static void LogEnvelopeError(this ILogger logger, string envelopeReceiverId, Exception? exception = null, string? message = null, params object?[] args)
public static string EncodeEnvelopeReceiverId(this long readOnlyId)
{
string combinedString = $"{Random.Shared.Next()}::{readOnlyId}::{Random.Shared.Next()}";
byte[] bytes = Encoding.UTF8.GetBytes(combinedString);
string base64String = Convert.ToBase64String(bytes);
return base64String;
}
public static void LogEnvelopeError(this ILogger logger, string envelopeReceiverId, Exception? exception = null, string? message = null, params object?[] args)
{
var sb = new StringBuilder().AppendLine(envelopeReceiverId.DecodeEnvelopeReceiverId().ToTitle());