How can I securly store an AES key in Windows with .Net (C#)?

后端 未结 5 2840
太阳男子
太阳男子 2021-02-20 18:08

I\'ve looking for a way to store a given AES key so that it can\'t be retrieved, but it can still be used for encryption and decryption (using C#). I think the equivalent for a

5条回答
  •  忘掉有多难
    2021-02-20 18:48

    @SLaks is right, if its in your memory it can be accessed. You can make it more difficult, but it's always going to be possible.

    That's why folks who are serious offload the crypto.

    One options is a smart card. This lets you move data to the card and get results back, but doesn't allow access to the key material. It's not in your PCs memory space so it can't be leaked.

    Ross Anderson has a good paper, Programming Satan's Computer about just this kind of thing. From the abstract:

    The problem is the presence of a hostile opponent, who can alter messages at will. In effect, our task is to program a computer which gives answers which are subtly and maliciously wrong at the most inconvenient possible moment.

    Even if you're not concerned about physical memory and just the hard disk and source you still need to be wary of virtual memory. If you're not careful (or using a carefully written service) you can get plaintext keys in your swap file. Here's another link that discusses the issue. Not that you want to do that but it makes the issue apparent: Encrypting Virtual Memory. I believe there are system calls for this purpose to mark memory as unswappable but I can't find a link.

提交回复
热议问题