대칭키 암호화 데이터 뷰테이블에서 복호화 하는 방법 / DecryptByKeyAutoCert

DataBase/MS-SQL|2018. 9. 12. 11:16
반응형

대칭키를 이용한 DB 암호화 처리 작업 시 


아래와 같이 대칭키와 인증서 OPEN 후 암복호화를 해야하는 것으로 알고 있었음.


OPEN SYMMETRIC 대칭키이름 DECRYPTION BY CERTIFICATE 인증서이름;


그런데 문제는 일반 프로시저나 웹 소스에서는 문제가 없으나


외부에 뷰테이블 형태로 제공하는 데이터가 있었는데 뷰테이블에서는 


그때까지만 해도.. OPEN SYMMETRIC 을 할수 없는게..아닌가..하고 난감했지만..




https://docs.microsoft.com/ko-kr/sql/t-sql/functions/decryptbykeyautocert-transact-sql?view=sql-server-2017


DecryptByKeyAutoCert 내장 함수를 사용하면 가능해진다는 것..





--Create the keys and certificate. USE AdventureWorks2012; CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'mzkvdlk979438teag$$ds987yghn)(*&4fdg^'; OPEN MASTER KEY DECRYPTION BY PASSWORD = 'mzkvdlk979438teag$$ds987yghn)(*&4fdg^'; CREATE CERTIFICATE HumanResources037 WITH SUBJECT = 'Sammamish HR', EXPIRY_DATE = '10/31/2009'; CREATE SYMMETRIC KEY SSN_Key_01 WITH ALGORITHM = DES ENCRYPTION BY CERTIFICATE HumanResources037; GO ----Add a column of encrypted data. ALTER TABLE HumanResources.Employee ADD EncryptedNationalIDNumber varbinary(128); OPEN SYMMETRIC KEY SSN_Key_01 DECRYPTION BY CERTIFICATE HumanResources037 ; UPDATE HumanResources.Employee SET EncryptedNationalIDNumber = EncryptByKey(Key_GUID('SSN_Key_01'), NationalIDNumber); GO -- --Close the key used to encrypt the data. CLOSE SYMMETRIC KEY SSN_Key_01; -- --There are two ways to decrypt the stored data. -- --OPTION ONE, using DecryptByKey() --1. Open the symmetric key --2. Decrypt the data --3. Close the symmetric key OPEN SYMMETRIC KEY SSN_Key_01 DECRYPTION BY CERTIFICATE HumanResources037; SELECT NationalIDNumber, EncryptedNationalIDNumber AS 'Encrypted ID Number', CONVERT(nvarchar, DecryptByKey(EncryptedNationalIDNumber)) AS 'Decrypted ID Number' FROM HumanResources.Employee; CLOSE SYMMETRIC KEY SSN_Key_01; -- --OPTION TWO, using DecryptByKeyAutoCert() SELECT NationalIDNumber, EncryptedNationalIDNumber AS 'Encrypted ID Number', CONVERT(nvarchar, DecryptByKeyAutoCert ( cert_ID('HumanResources037') , NULL ,EncryptedNationalIDNumber)) AS 'Decrypted ID Number' FROM HumanResources.Employee;


댓글()

ip 주소로 국가 조회하는 방법 about.ip2c.org API

Open API/그 외 |2018. 8. 30. 17:08
반응형

아이피주소로 국가 조회하기


서비스하는 내용이 국가별로 제한되는 부분이라


DB를 구축하자니 그 업데이트관리가 문제이고


API가 있지 않을까 해서 구글링을 통해 알게된 사이트입니다.



https://about.ip2c.org



Request : 


https://ip2c.org/8.8.8.8


Response : 


1;US;USA;United States


; 로 구분자가 지정되어있으며


0 : WRONG INPUT , 1 : NORMAL , 2 : UNKNOWN 


US : ISO 국가코드 








아래 내용은 about.ip2c.org 사이트에서 발췌한 INPUT/OUTPUT 설명입니다.

 
==== Accepted inputs: ============================================================

You can use http or https.

https://ip2c.org/XXX.XXX.XXX.XXX
or
https://ip2c.org/?ip=XXX.XXX.XXX.XXX
|
+ standard IPv4 from 0.0.0.0 to 255.255.255.255
+ e.g. we take your IP:
    |
    + URL looks like this:  https://ip2c.org/128.134.3.161
    |                       or
    |                       https://ip2c.org/?ip=128.134.3.161
    |
    + resulting string is:  1;KR;KOR;Korea Republic of


https://ip2c.org/XXXXXXXXXX
or
https://ip2c.org/?dec=XXXXXXXXXX
|
+ decimal number from 0 to 4294967295 (MAX_INT)
+ faster than ?ip= option, less server-side processing
+ to convert IPv4 to decimal you only need to know this:
    |
    + (IPv4) A.B.C.D == A*256^3 + B*256^2 + C*256 + D (decimal)
    + e.g.   5.6.7.8 == 5*256^3 + 6*256^2 + 7*256 + 8
                     == 5*16777216 + 6*65536 + 7*256 + 8
                     == 83886080 + 393216 + 1792 + 8
                     == 84281096


https://ip2c.org/s
or
https://ip2c.org/self
or
https://ip2c.org/?self
|
+ processes caller's IP
+ faster than ?dec= option but limited to one purpose - give info about yourself


Caution
Some clients (e.g. ASP) may have issues while trying to open a file over HTTP.
In that case a slash / preceding ?ip= is obligatory.
==== Possible outputs: ===========================================================

You can use http or https.

0;;;WRONG INPUT
|
+ your request has not been processed due to invalid syntax
    |
    + e.g. bad IPv4 like 300.400.abc.256
    + e.g. bad decimal like 2a3b4c or bigger than MAX_INT


1;CD;COD;COUNTRY
|
+ contains two-letter (ISO 3166) and three-letter country codes, and a full country name
+ country name may be multi-word and contain spaces
+ e.g. we take your IP:
    |
    + URL looks like this:  https://ip2c.org/128.134.3.161
    |                       or
    |                       https://ip2c.org/?ip=128.134.3.161
    |
    + resulting string is:  1;KR;KOR;Korea Republic of


2;;;UNKNOWN
|
+ given ip/dec not found in database or not yet physically assigned to any country


The first digit indicates status so you don't have to always parse the whole string.
Output is always semicolon delimited text/plain - you can pass it to any type of application.


댓글()

cmd 창에서 파일 속성 변경하기 - ATTRIB

OS/Microsoft|2018. 8. 30. 16:01
반응형


ATTRIB 명령어를 사용하면 파일의 속성을 변경할 수 있습니다.


우선 이 옵션을 찾아보게 된 계기가...


여러위치에 위치한 파일들의 읽기 전용 속성을 일괄 변경하기 위함이었습니다.



패치파일을 하나 생성 한뒤 r 옵션을 적용하는데 매우 간단 명료하게 

- , + 로 옵션을 적용 해제 합니다.


# 읽기전용 해제 시 
attrib -r "파일경로 및 파일명"

#읽기전용 적용 시
attrib +r "파일경로 및 파일명"




프롬프트창에서 확인 가능한 상세 옵션입니다.


(c) 2017 Microsoft Corporation. All rights reserved.


C:\Users\Administrator>Attrib /?

Displays or changes file attributes.


ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [+O | -O] [+I | -I] [+P | -P] [+U | -U]

       [drive:][path][filename] [/S [/D]] [/L]


  +   Sets an attribute.

  -   Clears an attribute.

  R   Read-only file attribute.

  A   Archive file attribute.

  S   System file attribute.

  H   Hidden file attribute.

  O   Offline attribute.

  I   Not content indexed file attribute.

  X   No scrub file attribute.

  V   Integrity attribute.

  P   Pinned attribute.

  U   Unpinned attribute.

  [drive:][path][filename]

      Specifies a file or files for attrib to process.

  /S  Processes matching files in the current folder

      and all subfolders.

  /D  Processes folders as well.

  /L  Work on the attributes of the Symbolic Link versus

      the target of the Symbolic Link



C:\Users\Administrator>




댓글()