public SerializedKey Serialize(RsaKey key)
        {
            string json = JsonSerializer.Serialize(key);

            return(new SerializedKey(
                       key,
                       DataProtectionCommonExtensions.Protect(_protector, json)));
        }
Exemple #2
0
    public void Unprotect_Success()
    {
        // Arrange
        Mock <IDataProtector> mockProtector = new Mock <IDataProtector>();

        mockProtector.Setup(p => p.Unprotect(new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 })).Returns(new byte[] { 0x48, 0x65, 0x6c, 0x6c, 0x6f });

        // Act
        string retVal = DataProtectionCommonExtensions.Unprotect(mockProtector.Object, "AQIDBAU");

        // Assert
        Assert.Equal("Hello", retVal);
    }
        public RsaKey Deserialize(SerializedKey serializedKey)
        {
            string json = DataProtectionCommonExtensions.Unprotect(_protector, serializedKey.Data);

            return(JsonSerializer.Deserialize <RsaKey>(json));
        }