Created
January 19, 2026 19:30
-
-
Save tiebingzhang/8390b2611c3a7e5e4c611c0e5260b3c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # AS2 Protocol Replication Script | |
| # Generates newfile.mime.txt, newfile.signed.txt, and newfile.encrypted.txt | |
| # Put the original content to be sent in file content.txt | |
| echo "Step 1: Creating MIME structure..." | |
| cat > newfile.mime.txt << 'EOF' | |
| Content-Type: application/edi-x12; name=message.edi | |
| Content-Transfer-Encoding: base64 | |
| Content-Disposition: attachment; filename=message.edi | |
| EOF | |
| base64 -i content.txt >> newfile.mime.txt | |
| echo "Step 2: Creating signed multipart structure..." | |
| # Use OpenSSL to create proper multipart/signed structure | |
| openssl smime -sign -in newfile.mime.txt -signer /tmp/partner-signing-cert.pem -inkey /tmp/signing-key.pem -out newfile.signed.txt | |
| echo "Step 3: Encrypting signed newfile..." | |
| openssl smime -encrypt -in newfile.signed.txt -out newfile.encrypted.txt /tmp/encryption-cert.pem | |
| echo "Step 4: Extracting raw encrypted data for AS2 transmission..." | |
| # Skip MIME headers and get just the base64 content | |
| awk '/^$/{flag=1;next} flag' newfile.encrypted.txt > newfile.encrypted.raw.txt | |
| echo "Step 5: Converting to binary format..." | |
| # Convert base64 to binary for Content-Transfer-Encoding: binary | |
| base64 -d -i newfile.encrypted.raw.txt -o newfile.encrypted.bin | |
| echo "AS2 protocol replication complete!" | |
| echo "Generated files:" | |
| echo "- newfile.mime.txt" | |
| echo "- newfile.signed.txt" | |
| echo "- newfile.encrypted.txt" | |
| echo "- newfile.encrypted.raw.txt (base64 data only)" | |
| echo "- newfile.encrypted.bin (binary for AS2 transmission)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment