Adding encrypted file into a database and retrieving them

Enkhbold Munkhbold 136 Reputation points
2020-07-22T01:29:27.87+00:00

Hi,

I'm trying to write an encrypted XML file into a database table and also read from it.
I use Microsoft SQL server management studio 18 and have a very basic database with a table containing XML digital signature file in one of its columns as a string(nvarchar(MAX)).
And now I want to encrypt it so it wouldn't be saved as a plain-text and with some added security.
I followed this walkthrough on Microsoft Learn: walkthrough-creating-a-cryptographic-application but I can't seem to get it working it throws "unable to read, invalid characters" exception when trying to read the file.

So my question is: How should I change the code provided in the walkthrough to correctly read the encrypted file from my database?

Thank you for your time.
Regards,
Enkhbold.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,783 questions
{count} votes

Accepted answer
  1. Peter Fleischer (former MVP) 19,326 Reputation points
    2020-07-23T06:16:45.36+00:00

    Hi Enkhbold,
    try following demo.

      <Window.DataContext>  
        <local:ViewModel/>  
      </Window.DataContext>  
      <StackPanel>  
        <Button Content="Create datatable on SQL Server" Command="{Binding Cmd}" CommandParameter="Create"/>  
        <Button Content="Insert encrypted xml to datatable" Command="{Binding Cmd}" CommandParameter="Insert"/>  
        <Button Content="Read from datatable and encrypt" Command="{Binding Cmd}" CommandParameter="Load"/>  
        <Button Content="Test encrypt - decrypt" Command="{Binding Cmd}" CommandParameter="Test"/>  
        <TextBlock Text="{Binding Info}"/>  
      </StackPanel>  
    

    --------------------------------------------------------------------------

    The forum software deny show whole code. I will prepare upload.

    Sorry, in this buggy forum include link is prohibited, see pictures:

    13447-x1.png

    13502-x2.png

    You can find demo in Github under https://github.com/fips1950/EnDeCrypt_Demo_EnkhboldMunkhbold-5136

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Leon Laude 85,816 Reputation points
    2020-07-22T07:14:52.99+00:00

    Hi,

    .NET development is currently not supported in the Q&A forums, the supported products are listed over here https://learn.microsoft.com/en-us/answers/products (more to be added later on).

    You can ask the experts in the dedicated .NET development forums over here:
    https://dotnet.microsoft.com/platform/community

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=netdevelopment

    (Please don't forget to accept helpful replies as answer)

    Best regards,
    Leon


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.