PowerShell 을 사용하여 MachineKey 를 작성하는 방법입니다.


Appendix A: How to generate a <machineKey> element

아래 Function 을 PowerShell 에 Copy & Paste 하여 Enter 를 쾅! 칩니다. ^^


# Generates a <machineKey> element that can be copied + pasted into a Web.config file.
function Generate-MachineKey {
  [CmdletBinding()]
  param (
    [ValidateSet("AES", "DES", "3DES")]
    [string]$decryptionAlgorithm = 'AES',
    [ValidateSet("MD5", "SHA1", "HMACSHA256", "HMACSHA384", "HMACSHA512")]
    [string]$validationAlgorithm = 'HMACSHA256'
  )
  process {
    function BinaryToHex {
        [CmdLetBinding()]
        param($bytes)
        process {
            $builder = new-object System.Text.StringBuilder
            foreach ($b in $bytes) {
              $builder = $builder.AppendFormat([System.Globalization.CultureInfo]::InvariantCulture, "{0:X2}", $b)
            }
            $builder
        }
    }
    switch ($decryptionAlgorithm) {
      "AES" { $decryptionObject = new-object System.Security.Cryptography.AesCryptoServiceProvider }
      "DES" { $decryptionObject = new-object System.Security.Cryptography.DESCryptoServiceProvider }
      "3DES" { $decryptionObject = new-object System.Security.Cryptography.TripleDESCryptoServiceProvider }
    }
    $decryptionObject.GenerateKey()
    $decryptionKey = BinaryToHex($decryptionObject.Key)
    $decryptionObject.Dispose()
    switch ($validationAlgorithm) {
      "MD5" { $validationObject = new-object System.Security.Cryptography.HMACMD5 }
      "SHA1" { $validationObject = new-object System.Security.Cryptography.HMACSHA1 }
      "HMACSHA256" { $validationObject = new-object System.Security.Cryptography.HMACSHA256 }
      "HMACSHA385" { $validationObject = new-object System.Security.Cryptography.HMACSHA384 }
      "HMACSHA512" { $validationObject = new-object System.Security.Cryptography.HMACSHA512 }
    }
    $validationKey = BinaryToHex($validationObject.Key)
    $validationObject.Dispose()
    [string]::Format([System.Globalization.CultureInfo]::InvariantCulture,
      "<machineKey decryption=`"{0}`" decryptionKey=`"{1}`" validation=`"{2}`" validationKey=`"{3}`" />",
      $decryptionAlgorithm.ToUpperInvariant(), $decryptionKey,
      $validationAlgorithm.ToUpperInvariant(), $validationKey)
  }
}


그러면 추가한 Generate-MachineKey 를 사용해 봐야겠죠?!


ASP.NET 4.0 application 에서는 Machine Key 작성시 Option Parameter 를 주지 않아도 됩니다.


PS> Generate-MachineKey

<machineKey decryption="AES" decryptionKey="..." validation="HMACSHA256" validationKey="..." />


하지만 ASP.NET 2.0 과 3.5 application 에서는 HMACSHA256 을 지원하지 않으므로 Parameter 로 "SHA1" 을 넣어줘야 한다네요.


PS> Generate-MachineKey -validation sha1

<machineKey decryption="AES" decryptionKey="..." validation="SHA1" validationKey="..." />


ASP.NET 그리고 Web.config 파일에 MachineKey element 를 추가해 줍니다.


<configuration>

  <system.web>

    <machineKey ... />

  </system.web>

</configuration>


행복한 고수되셔요.



woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

반응형



Time Zone Identifiers 정보입니다.

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/bb384272%28v%3dvs.90%29


UTC Time 을 Localtime 으로 변경하시려면...


TimeZoneInfo koreaStandardTimeZone 

= TimeZoneInfo.FindSystemTimeZoneById("Korea Standard Time");

DateTime koreaStandardTime 

= TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, koreaStandardTimeZone);

MessageBox.Show(koreaStandardTime.ToString("yyyy-MM-dd HH:mm:ss"));



이렇게 사용하시면 되겠습니다.



행복한 고수되셔요. ^^

woojja ))*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

반응형

'.NET' 카테고리의 다른 글

[.NET] DataTable to Dictionary using Linq  (0) 2022.01.14
[.NET] .NET MAUI 를 소개합니다.  (0) 2021.11.26
[.NET] Clone  (0) 2017.05.31
[.NET] Collection was modified; enumeration operation may not execute.  (4) 2017.05.30
[.NET] .NET Core Roadmap  (0) 2017.02.10

Node.JS 테스트 중 CentOS 에 rpmforge 를 설치해야만 하게 됐는데요.


찾았던 자료들이 너무 오래되어서 Download Site 가 사라져버려 접속이 안되고 있었습니다.


그래서 업데이트 한 링크를 바탕으로 설치하는 방법입니다.


내용은 

https://centos.pkgs.org/6/repoforge-x86_64/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm.html

에 있습니다.



  1. Download the latest rpmforge-release rpm from
    http://ftp.tu-chemnitz.de/pub/linux/dag/redhat/el6/en/x86_64/rpmforge/RPMS/
  2. Install rpmforge-release rpm:
    # rpm -Uvh rpmforge-release*rpm
  3. Install rpmforge-release rpm package:
    # yum install rpmforge-release


1. wget http://ftp.tu-chemnitz.de/pub/linux/dag/redhat/el6/en/x86_64/rpmforge/RPMS/  로 Download 받습니다.

2. sudo rpm -Uvh rpmforge-release*rpm 을 실행하여 설치합니다.

3. sudo yum install rpmforge-release 로 Package 를 설치합니다.


다음 산을 넘으러 가보겠습니다.


행복한 고수되십시요. 


woojja ))*

₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩₩

반응형

+ Recent posts