LoginSignup
1
1

More than 1 year has passed since last update.

.NET 5での気づきを記録していくメモ

Last updated at Posted at 2020-07-19

おもに「.NET Frameworkではできてたけど.NET 5に移行して実装の修正が必要となった」点について気づきを記録していきます。.NET Frameworkで実装した既存資産を、.NET 5に移行する際の注意点を具体化できればいいかなと思います(ほとんど書くことないかも…)。

なお、この記事は育てる記事なので随時追記予定。

ファイルのアクセスコントロール

File.GetAccessControlは、.NET 5では使用できないため、FileInfo.GetAccessControlを使用します。事前にNuGetパッケージSysem.IO.FileSystem.AccessControlのインストールが必要です。

ファイルのアクセスコントロールにEveryone・FullControlを付与
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var info = new FileInfo(@"C:\usr\local\sample.txt");
            var security = info.GetAccessControl();

            security.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                FileSystemRights.FullControl, AccessControlType.Allow));
            info.SetAccessControl(security);
        }
    }
}

【参考】Add “Everyone” privilege to folder using C#.NET

Rijndaelのブロック長

Rijndaelのブロック長について、.NET Framwrokでは128 ビットまたは256 ビットを指定可能でしたが、.NET Coreからは128 ビット固定です。

using (RijndaelManaged rdm = new RijndaelManaged())
{
    //rdm.BlockSize = 256; // System.PlatformNotSupportedException: BlockSize must be 128 in this implementation.
    rdm.BlockSize = 128;

【参考】256 blocksize does not work in .net core #13

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1