feat(EnvelopeReceiverReadOnly): Erweiterungsmethode zum Kodieren und Dekodieren von Envelope-Receiver ReadOnly Id hinzugefügt
This commit is contained in:
parent
370666cb0e
commit
54e86b421c
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application
|
namespace EnvelopeGenerator.Application
|
||||||
@ -88,6 +89,22 @@ namespace EnvelopeGenerator.Application
|
|||||||
return (string.Empty, string.Empty);
|
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>
|
/// <summary>
|
||||||
/// Gets the envelope UUID from the decoded envelope receiver ID.
|
/// Gets the envelope UUID from the decoded envelope receiver ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -111,7 +128,16 @@ namespace EnvelopeGenerator.Application
|
|||||||
return base64String;
|
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());
|
var sb = new StringBuilder().AppendLine(envelopeReceiverId.DecodeEnvelopeReceiverId().ToTitle());
|
||||||
|
|
||||||
|
|||||||
@ -40,13 +40,27 @@ namespace EnvelopeGenerator.Web.Controllers.Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("decode")]
|
[HttpGet("decode")]
|
||||||
public IActionResult DecodeEnvelopeReceiverId(string envelopeReceiverId)
|
public IActionResult DecodeEnvelopeReceiverId(string envelopeReceiverId, bool isReadOnly = false)
|
||||||
{
|
{
|
||||||
var decoded = envelopeReceiverId.DecodeEnvelopeReceiverId();
|
if (isReadOnly)
|
||||||
return Ok(new { uuid = decoded.EnvelopeUuid, signature = decoded.ReceiverSignature });
|
{
|
||||||
|
var (Random1, ReadOnlyId, Random2) = envelopeReceiverId.DecodeEnvelopeReceiverReadOnlyId();
|
||||||
|
return Ok(new { random = new string?[] { Random1, Random2 }, readOnlyId = ReadOnlyId });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var (EnvelopeUuid, ReceiverSignature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
|
||||||
|
return Ok(new { uuid = EnvelopeUuid, signature = ReceiverSignature });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("encode")]
|
[HttpGet("encode")]
|
||||||
public IActionResult EncodeEnvelopeReceiverId(string uuid, string signature) => Ok((uuid, signature).EncodeEnvelopeReceiverId());
|
public IActionResult EncodeEnvelopeReceiverId(string? uuid = null, string? signature = null, long? readOnlyId = null)
|
||||||
|
{
|
||||||
|
if(readOnlyId is long readOnlyId_long)
|
||||||
|
return Ok(readOnlyId_long.EncodeEnvelopeReceiverId());
|
||||||
|
else
|
||||||
|
return Ok((uuid ?? string.Empty, signature ?? string.Empty).EncodeEnvelopeReceiverId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user