메뉴 건너뛰기

infra

[xmlsec] xpath를 이용한 암호화(aes, tripledes)

박영식2010.05.17 22:27조회 수 3620댓글 0

    • 글자 크기
aes를 이용한 암호화는 아래와 같이 xpath를 이용할 수 있다.

$ xmlsec1 encrypt --aeskey key.bin --xml-data <inputfile> --output <outputfile> --node-xpath /PaymentInfo/CreditCard <templetfile>

$ xmlsec1 decrypt --aeskey key.bin <inputfile>


템플릿 파일은
<?xml version='1.0'?>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
  <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes192-cbc"/>
  <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <KeyName/>
  </KeyInfo>
  <CipherData>
    <CipherValue/>
  </CipherData>
</EncryptedData>

위와 같고, 전체 암호화 템플릿 파일과 다른 점은  Type="http://www.w3.org/2001/04/xmlenc#Element" 이 추가되었는 것이다.

des는 템플릿 파일이 Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/ 만 지원한다는 점이 한계점이고,


$ xmlsec1 encrypt --deskey key.bin --xml-data <inputfile> --output <outputfile> --node-xpath /PaymentInfo/CreditCard <templetfile>

$ xmlsec1 decrypt --deskey key.bin <inputfile>

위과 같이 --deskey 옵션만 주면 된다.

--binary-data와 --xml-data의 중요한 차이점이 있다. --binary-data는 --node-xpath 옵션을 지원하지 않는다.
--xml-data 는 템플릿 파일 EncryptedData 속성에 반드시 Type을 포함해야 한다.

aes192-cbc 템플릿으로 암호화 한 결과이다.


$ xmlsec1 encrypt --aeskey:aes-192 key.bin --xml-data /tmp/inPUoQxA --output /tmp/outwnIk8j --node-xpath /PaymentInfo/CreditCard

<?xml version="1.0"?>
<PaymentInfo xmlns="">
  <Name>John Smith</Name>
  <EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
  <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes192-cbc"/>
  <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <KeyName>aes-192</KeyName>
  </KeyInfo>
  <CipherData>
    <CipherValue>1IJ7iJrDksB9XubM8FNIGZK6JthlVR5jQSkXg/dPNLeQwcjuZ0IQOU5CTTU+7hkM
JggCAeR5Tfmm4mKX6PMepPM0XCXpRIpwvvfZjOtU7gfxnsLu8dq4mnFNyvQZjOqX
faGr8SweM+YwVbhYW3bw04mUlA71CmkbcrSrALUtZFfrMF2/N8MX2EFRj+dUYufU
gygc4Tt+CbgxeXt0ZTps9FAuj7bgxwK5GTbmORfjSnV/Mz/13f6Rrlcx8M/bctOh</CipherValue>
  </CipherData>
</EncryptedData>
  <etc>data</etc>
</PaymentInfo>

aeskey 뒤에 :키네임 해주면 결과파일에 keyname이 들어간다.
박영식 (비회원)
    • 글자 크기

댓글 달기

첨부 (0)
위로