C#,Dapper,POCO和Encrypt / Decrypt

时间:2017-01-20 01:15:21

标签: c# sqlite encryption dapper poco

我有这个POCO课程:

Sub BMI()
     'variable declaration
        Dim ws As Worksheet
        Dim ch As Chart
        Dim trend As Trendline
        Dim rng As Range
        Dim i As Long

    Set ws = ThisWorkbook.Sheets("Sheet2")
    Set rng = ws.Range("$A$3:$N$3")

    For i = 0 To 1
    With ws

        Set ch = ThisWorkbook.Sheets("Sheet3").Shapes.AddChart.Chart
        ch.ChartType = xlColumnClustered
        ch.SetSourceData Source:=Range(.Name & "!" & rng.Offset(i, 0).Address)
        Set trend = ch.SeriesCollection(1).Trendlines.Add(xlLinear)
            With trend.Border
                .ColorIndex = 33
                .Weight = xlMedium
                .LineStyle = xlDashDotDot
            End With
        'Left & top are used to adjust the position of chart on sheet


        ch.ChartArea.Width = 500
        ch.ChartArea.Height = 300
        ch.ChartArea.Left = 200
        ch.ChartArea.Top = (i) * ch.ChartArea.Height + (50 * (i + 1))
    End With

   With ws
         ' Belllow code just to  Add a title.
        ch.HasTitle = True
        With ch.ChartTitle
            .Text = ws.Range("A3").Offset(i, 0)

            ' Set the orientation of the title.
            ' Horizontal is the default, but you can change it
            ' to something else.
            .Orientation = XlOrientation.xlHorizontal

            ' You can format individual characters, or
            ' the entire title:
            With .Characters(1, 1).Font
                .Size = 24
                .Color = rgbDarkBlue

            End With

            .Characters(2).Font.Size = 14

            With .Format

                .Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent1
                With .Shadow
                    .ForeColor.ObjectThemeColor = msoThemeColorAccent4
                    .Style = msoShadowStyleOuterShadow
                    .OffsetX = 4
                    .OffsetY = 4
                End With
            End With

            ' Make sure and leave room for the title in the chart.
            .IncludeInLayout = True
        End With
    End With
     ' code just to  Add a title finish.


    Set ch = Nothing
    Set trend = Nothing

Next

Set rng = Nothing
Set ws = Nothing

End Sub

当我从数据库中读取数据以及从C#访问POCO对象时,如何加密/解密class Users { public string User { get; set; } public string Password { get; set; } private string Encrypt(string plainText) { ... return encryptedText; } private string Decrypt(string cipherText) { ... return decryptedText; } 字段?

我试图像这样使用某些东西:

Password

但是当对象填充了我的数据库中的数据时,一切正常,class Users { private string _password; public string User { get; set; } public string Password { get { return Encriptar(_password); } set { _password = Desencriptar(value); } } private string Encrypt(string plainText) { ... return encryptedText; } private string Decrypt(string cipherText) { ... return decryptedText; } 字段正确解密,但是当我从C#访问一个对象以显示在文本字段中时,Password属性再次收录我的数据:/

1 个答案:

答案 0 :(得分:0)

这与Dapper无关。还要考虑其他人发布的评论问题。

以下只是建议如何在get块中避免解密两次。

private string _password;
private bool _isDecrypted = false;
public string Password
{
    get
    {
        if(_isDecrypted == false)
        {
            _password = Decrypt(_password);
            _isDecrypted = true;
        }
        return (_password);
    }
    set
    {
        _password = Encrypt(value);
        _isDecrypted = false;
    }
}