PKCS7 암호화

PKCS7 암호화

나는 당신의 지원이 필요합니다. pkcs 암호화에 내 인증서와 타사 인증서를 사용하고 싶습니다.

다음 구성 요소가 있고 pkcs7 암호화된 출력 파일을 원합니다.

소스 파일: PayFile_143_2300000004_20170508_161457.txt 내 로그인 자격 증명:

mycertificate.cer 및 해당 개인 키는 keyfile.key입니다. 제3자 은행 인증서(공개): public_2017-2018_base64enc.cer

따라서 다음 명령을 사용하면

openssl smime -sign -signer mycertificate.cer -inkey keyfile.key -in PayFile_143_2300000004_20170508_161457.txt | openssl smime -encrypt -out PayFile_143_2300000004_20170508_161457.txt.smime public_2017-2018_base64enc.cer mycertificate.cer

PKCS7 암호화된 출력 파일에 대한 올바른 출력을 얻을 수 있습니까? 말해주세요.

그러나 은행이 터미널에서 암호를 해독할 때 헤더 문제에 직면합니다.

다음은 은행에서 제공한 복호화 로그이다.

starting ReceiveMsg...
logging in...
login successful
getting decryption key and verification certificate...
decryption key and verification certificate extracted
creating mime session
session created
opening mime envelope
message Content-Type [application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"]
message Content-Description [null]
message Content-Disposition [attachment]
message Content-Transfer-Encoding [base64]
getting mime message content
content handler [oracle.security.crypto.smime.SmimeEnveloped]
---------------------------------------
processing encrypted content
content decrypted
decrypted Content-Type [multipart/signed; protocol="application/x-pkcs7-signature"; micalg="sha1"; boundary="----DA713A069014AEA715F4E38046E2CA0F"]
content handler [oracle.security.crypto.smime.SmimeMultipartSigned]
-Multipart 1-
Multipart Content-Type [multipart/signed; protocol="application/pkcs7-signature";
      boundary="SMS:gW4H/s2Z6GzgMG1DTTNnUi3TmH8="]
Multipart contains [2] body parts
Part 0 Content-Type [text/plain]
Part 0 Content-Description [null]
Part 0 Content-Disposition [null]
Part 0 Content-Transfer-Encoding [null]
Part 0 Content-ID [null]
Part 0 Content-Language [null]
Part 0 Content-MD5 [null]
Part 0 File-Name [null]
Part 0 Header name [], value [20:61]
Part 0 Header name [], value [23B:CRED]
Part 0 Header name [], value [32A:170508RUB100,00]
Part 0 Header name [], value [50K:/40702810200101102376]
Part 0 Header name [???7743170710.???774301001], value [???7743170710.???774301001]
Part 0 Header name [], value [57D://RU044525460.40702840401735933455]
Part 0 Header name [??? ?????????], value [??? ?????????]
Part 0 Header name [115054, ?????????? ???????, ??? 2, ?????], value [115054, ?????????? ???????, ??? 2, ?????]
Part 0 Header name [??????,,RU,], value [??????,,RU,]
Part 0 Header name [], value [59:/40702840401735933455]
Part 0 Header name [???7704662571.???770901001], value [???7704662571.???770901001]
Part 0 Header name [??? "????? ?????? ????? ???????"], value [??? "????? ?????? ????? ???????"]
Part 0 Header name [,??.???????? ???,9], value [,??.???????? ???,9]
Part 0 Header name [??????,,RU,105064], value [??????,,RU,105064]
Part 0 Header name [], value [70:??????????, ???????? ???? ????????? ? ????????????]
Part 0 Header name [], value [71A:SHA]
Part 0 Header name [], value [72:/RPP/61.170508.3.ELEK.170508]
content handler [java.lang.String]
-Multipart 1-
Content-Type=Cp1251
charset=null
writing text mime data to file 
data length=0
data =
done...

확인해 보시고 어디가 문제인지 알려 주실 수 있나요

도와주셔서 감사합니다! ! 고마워요 니힐

답변1

은행이 암호를 해독하는 것 같지만 서명된 파일을 나타내는 SMIME을 구문 분석할 수 없습니다. 이거 이메일로 보냈나요? "-outform PEM"을 사용하여 서명 파일 형식을 변경해 보셨나요?

openssl smime -sign -signer mycertificate.cer -inkey keyfile.key -in PayFile_143_2300000004_20170508_161457.txt -outform PEM | openssl smime -encrypt -out PayFile_143_2300000004_20170508_161457.txt.smime public_2017-2018_base64enc.cer mycertificate.cer

다음은 서명되고 암호화된 메시지를 보내는 짧은 스크립트입니다. 환경 변수를 귀하와 귀하의 은행에 대한 값으로 바꾸십시오. 또한 cert.pem과 key.pem을 사용합니다. 이는 인증서와 키 파일이 PEM 형식인지 DER 형식인지 쉽게 식별할 수 있도록 제가 선호하는 것입니다. 이 내용은 2013년 2월 11일 OpenSSL 1.0.1e-fips를 사용하여 CentOS 7에서 작성 및 테스트되었습니다. Postfix는 MTA이므로 "sendmail" 명령은 "Postfix to Sendmail 호환성 인터페이스"입니다.

#!/bin/bash

FROM="Your Name <[email protected]>"
FROMCERT=cert.pem
FROMKEY=key.pem
[email protected]
TOCERTS="bankcert.pem cert.pem"
SUBJECT="Signed and Encrypted Email Test - $(date)"

(echo -e "Content-Type: text/plain; charset=windows-1251\n"; cat file.txt) \
| openssl smime -sign \
  -signer ${FROMCERT} \
  -inkey ${FROMKEY} \
| openssl smime -encrypt \
  -from "${FROM}" \
  -to "${TO}" \
  -subject "${SUBJECT}" \
  -des3 \
  ${TOCERTS} \
| sendmail -t -f "${FROM}" -F "${FROM}"

관련 정보