<PackageReference Include="BouncyCastle.Cryptography" Version="2.7.0" />

Org.BouncyCastle.Pkcs.Pkcs12Utilities

public class Pkcs12Utilities
Utility class for re-encoding PKCS#12 files to definite length.
public Pkcs12Utilities()

public static byte[] ConvertToDefiniteLength(byte[] berPkcs12File)

Just re-encode the outer layer of the PKCS#12 file to definite length encoding.

public static byte[] ConvertToDefiniteLength(byte[] berPkcs12File, char[] passwd)

Re-encode the PKCS#12 structure to definite length encoding at the inner layer as well.