SYSLIB0060: Rfc2898DeriveBytes 생성자가 더 이상 사용되지 않음.

.NET 10부터 System.Security.Cryptography.Rfc2898DeriveBytes 모든 생성자는 사용되지 않습니다. 코드에서 이러한 생성자를 호출하면 컴파일 시간에 경고 SYSLIB0060 생성됩니다.

사용되지 않는 이유

System.Security.Cryptography.Rfc2898DeriveBytes 제공하는 PBKDF2의 인스턴스 기반 구현은 GetBytes연속 호출을 허용하여 바이트를 다시 "스트리밍"하여 비표준 사용을 제공합니다. 이는 PBKDF2의 의도된 사용이 아닙니다. 알고리즘은 원샷으로 사용해야 합니다. 원샷 기능은 정적 메서드 Rfc2898DeriveBytes.Pbkdf2 존재하며 System.Security.Cryptography.Rfc2898DeriveBytes인스턴스화하는 대신 사용해야 합니다.

해결 방법

대신 System.Security.Cryptography.Rfc2898DeriveBytes 원샷 정적 메서드를 사용하도록 GetBytes 인스턴스를 변경하고 Rfc2898DeriveBytes.Pbkdf2 호출합니다.

예를 들어 다음 코드를 변경합니다.

Rfc2898DeriveBytes kdf = new Rfc2898DeriveBytes(password, salt, iterations, hashAlgorithm);
byte[] derivedKey = kdf.GetBytes(64);

다음과 같이:

byte[] derivedKey = Rfc2898DeriveBytes.Pbkdf2(password, salt, iterations, hashAlgorithm, 64);

솔트 Rfc2898DeriveBytes 크기를 사용하는 생성자를 사용한 경우 솔트를 수동으로 만들어야 합니다(Rfc2898DeriveBytes.Pbkdf2 솔트 크기를 사용하는 오버로드가 없습니다). 이전 구현과의 일관성을 위해 기존 배열을 암호화된 보안 바이트로 채우거나 RandomNumberGenerator.Fill 암호화된 보안 바이트로 새 배열을 만드는 데 사용합니다RandomNumberGenerator.GetBytes.

예를 들어 다음 코드를 변경합니다.

Rfc2898DeriveBytes kdf = new Rfc2898DeriveBytes(password, saltSize, iterations, hashAlgorithm);
byte[] salt = kdf.Salt;
byte[] derivedKey = kdf.GetBytes(64);

다음과 같이:

byte[] salt = RandomNumberGenerator.GetBytes(saltSize);
byte[] derivedKey = Rfc2898DeriveBytes.Pbkdf2(password, salt, iterations, hashAlgorithm, 64);

경고 표시 안 함

사용되지 않는 API를 사용해야 하는 경우 코드 또는 프로젝트 파일에서 경고를 표시하지 않을 수 있습니다.

단일 위반만 표시하지 않으려면 소스 파일에 전처리기 지시문을 추가하여 경고를 사용하지 않도록 설정한 다음 다시 사용하도록 설정합니다.

// Disable the warning.
#pragma warning disable SYSLIB0060

// Code that uses obsolete API.
// ...

// Re-enable the warning.
#pragma warning restore SYSLIB0060

프로젝트의 모든 SYSLIB0060 경고를 억제하려면 프로젝트 파일에 <NoWarn> 속성을 추가하세요.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   ...
   <NoWarn>$(NoWarn);SYSLIB0060</NoWarn>
  </PropertyGroup>
</Project>

자세한 내용은 경고 표시 안 함참조하세요.