메뉴 건너뛰기

infra

[xmlsec] xpath를 이용한 element 암호화(Encryption of a single value)

박영식2010.05.07 19:21조회 수 3695댓글 0

  • 2
    • 글자 크기
http://www.dcc.uchile.cl/~pcamacho/tutorial/web/xmlsec/xmlsec.html

위 주소에 잘 나와있다. 테스트 해본 결과를 정리해 보았다.

해당 사이트에서는 key에 대한 정보를 제공한다. 이 key 정보 파일이 있어야 예제들을 테스트 해 볼 수 있다.

encryption 때는 password를 묻지 않으나, decryption 때, password를 물어본다. hello 라고 입력하면 된다.

여기에도 해당 사이트에서 제공하는 파일을 업로드 한다.

디지털 서명에 대한 것은 오픈소스프로젝트를 진행하면서 테스트할 것이라 여기에선 다루지 않는다.

이 게시글의 밑의 글에 추가하여 노드와 value대한 암호에 대해만 적는다.

필요한 파일은 pub-userkey.pem (공개키), doc-plain.xml (평문 xml), session-key-template.xml (암호화 문서 템플릿), userkey.pem (개인키) 이다.

암호화를 위해서 해당 파일을 system이 writing 가능한 디렉터리에 복사한다.

{doc-plain.xml}
<?xml version="1.0" encoding="utf-8" ?> 
<PayInfo>
<Name>John Smith</Name>
<CreditCard Limit='2,000' Currency='USD'>
<Number>1076 2478 0678 5589</Number>
<Issuer>CitiBank</Issuer>
<Expiration>06/10</Expiration>
</CreditCard>
</PayInfo>


$ xmlsec encrypt --pubkey-pem pub-userkey.pem --session-key des-192 --xml-data doc-plain.xml  --output doc-encrypted-xpath.xml --node-xpath '/PayInfo/CreditCard/Number/text()' session-key-template.xml
 

{doc-encrypted-xpath.xml}
<?xml version="1.0" encoding="utf-8"?>
<PayInfo>
<Name>John Smith</Name>
<CreditCard Limit="2,000" Currency="USD">
<Number><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#tripledes-cbc"/>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName/>
</KeyInfo>
<CipherData>
<CipherValue>lcabQmBPTsQ4Fd4GAz0/KqyWE1JCZVMKXd1PYfmtrdi1JtfZpt647rvJX585/1pP
4GeE3N1zyeKS3QKWTIArib3i/ZxZPlNqk2e/CDMCVXYTPQjpSCLENewb8swRLFd6
wBqP5NsiyIaNmQquGgexeqrqqgJF1XJUkWeXqk1Xd3I=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>46M4nvxmrnqWKcwhrGfotkIhACQoi0w4PhuQBSfb8CQ=</CipherValue>
</CipherData>
</EncryptedData></Number>
<Issuer>CitiBank</Issuer>
<Expiration>06/10</Expiration>
</CreditCard>
</PayInfo>

해당 페이지에는 


xmlsec encrypt --pubkey-pem pub-userkey.pem
  --session-key des-192 --xml-data doc-plain.xml 
  --output doc-encrypted-xpath.xml
  --node-xpath /PayInfo/CreditCard/Number/text()
  session-key-template.xml

위와 같은 코드로 나와있다.  옵션의 --node-xpath 표현식에 싱글 쿼트(')가 없으면
 
bash : syntax error near unexpected token `('
 
에러가 난다.

복호화는 캡쳐 화면을 참고하기 바란다.

$ xmlsec decrypt --privkey-pem userkey.pem doc-encrypted-xpath.xml
(언급했듯이 password는 hello이다)

2.PNG

박영식 (비회원)
  • 2
    • 글자 크기
[xmlsec] 서명용 keyfile 생성과 서명하기 (by 박영식) [xmlsec1] 설치와 test (by 박영식)

댓글 달기

박영식
2011.03.17 조회 1710
박영식
2011.03.07 조회 2059
박영식
2010.04.22 조회 3235
박영식
2010.01.09 조회 3316
첨부 (2)
2.PNG
50.2KB / Download 75
xmlsec_xpath.zip
2.0KB / Download 70
위로