Base64 encode can be achieved by
$ echo Some_data_to_be_converted | base64U29tZV9kYXRhX3RvX2JlIF9jb252ZXJ0ZWQK
And Base64 decode can be achieved by
$ echo U29tZV9kYXRhX3RvX2JlIF9jb252ZXJ0ZWQK | base64 -dSome_data_to_be_converted
How to achieve Base64URL encode/decode?
Is it just enough to replace "+" with "-" and "/" with " _" ?
When to do the padding "#"(adding/remove "#" to be considered )?
I'm trying to read the eml file and save the attachments using a Java and Tomcat 9.But I have a problem when I manage this content type:
Content-Type: application/pdf; name="=?utf-8?Q?Men=C3=B9_Miki_travel=2Epdf?="Content-Disposition: attachment;filename="=?utf-8?Q?Men=C3=B9_Miki_travel=2Epdf?="Content-Transfer-Encoding: base64
If I try to print the content type I have this output, what is this format?:
application/pdf; name="=?utf-8?Q?Men=C3=B9_Miki_travel=2Epdf?="
Why in content type is there the name?How can I manage It and convert the name in the real name (Menu' My Restaurant.pdf) managing the spaces and special caracters?
MimeMultipart mimeMultipart = (MimeMultipart) message.getContent(); emlBody = getTextFromMimeMultipart(mimeMultipart); Multipart multiPart = (Multipart) message.getContent(); int numberOfParts = multiPart.getCount(); for (int partCount = 0; partCount < numberOfParts; partCount++) { MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount); if(part.getFileName()!=null) { //define variable String strAttachment = ""; String myFileName = part.getFileName(); if (part.getContentType().toLowerCase().contains("application/pdf; name=")) { System.out.println("Conentype: " + part.getContentType()); myFileName = "attach"+ partCount + ".pdf"; } //define variable String myPathSave = mypath + myFileName; String myPathHref = mypathHref + myFileName; try { if (partCount==1) { strAttachment = "<B>Attachment:</B>"; } else { strAttachment = ""; } part.saveFile(myPathSave); } catch (IOException exc) { System.out.println(exc.toString()); } } }
I have to encode an array of bytes to a base64 string (and decode this string) on an old Delphi 2007.How could I do?
Further Informations:
I've tried synapse (As suggested here Binary to Base64 (Delphi)).
I am working on a project where we have to classify e-mails. For this project I need to extract ALL text from the e-mails and their attachments.
My problem is that some attachments are of the type "application/pkcs7-mime", and I am not sure how to handle those.
import email, base64# Opening messageeml_file = '/path/to/file.eml'message = email.message_from_file(open(eml_file))# Printing content typesfor part in message.walk(): print(part.get_content_type())>multipart/mixed text/plain message/rfc822 application/pkcs7-mime
The part that is giving the problems is "application/pkcs7-mime". Next I try to extract data from the payload.
# Ensuring we got the right payloadmessage.get_payload(1).get_payload(0).get_content_type()>application/pkcs7-mime# Getting payloadmessage.get_payload(1).get_payload(0).get_payload()MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwGggxDhqwSDEOGmQ29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PV8wMDRfRkVGNjMyNEIyNDFFNDA5MEFBMUQ3RUQ5QUZBQkZFMDdic2Vka187DQogbWljYWxnPXNoYTI1Ng0KDQotLV8wMDRfRkVGNjMyNEIyNDFFNDA5MEFBMUQ3RUQ5QUZBQkZFMDdic2Vka18NCkNvbnRlbnQtVHlwZTogdGV4dC9odG1sOyBjaGFyc2V0PXV0Zi04DQpDb250ZW50LUlEOiA8Mzg3NTg2Nzk0M0UzNkY0OUEzQjcy.......
It looks like the payload is encoded in base64, so I try to decode it:
# Decoding messagemessage.get_payload(1).get_payload(0).get_payload(decode=True).decode("iso-8859-1")# Top of output á«á¦Content-Type: multipart/mixed; boundary=_004_FEF6324B241E4090AA1D7ED9AFABFE07bsedk_; micalg=sha256--_004_FEF6324B241E4090AA1D7ED9AFABFE07bsedk_Content-Type: text/html; charset=utf-8Content-ID: <3875867943E36F49A3B72D0FAEB1DC35@eurprd01.prod.exchangelabs.com>Content-Transfer-Encoding: base64PGh0bWwgeG1sbnM6bz0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTpvZmZpY2U6b2ZmaWNlIiB4bWxuczp3PSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTp3b3JkIiB4bWxuczptPSJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL29mZmljZS8yMDA0LzEyL29tbWwiIHhtbG5zPSJo# Bottom of output0U 0U00, * (&http://crl.oces.trust2408.com/oces.crl0\ Z X¤V0T10 UDK10U×ÿÑE|g¢¿ºÊ]6¾ãñJfYéÿBû´s²J7ª¡-*¨ Ø p@6¨Ë9ǦíæýÕUB9Íõ £àg&7î!Ö®?sÒ8Wè>º|mIh +|2¨Ü%«O´|%o¬¦¥ð¶oòÝ¿t³ é¾ÏPÒëqûW®ö8|¼èÇçqQL ½þ¹Ù`¶¿*7ÒýsÎKb!ÿ¶?:{¸½Ú\õ{ÕþyÅI.éÃÂKèj36q°lD}|RÎàIzÙ/^[j;3¶Ðà+®r$¥!1ß0Û0I0A10 UDK10UªÏÒ¶,`§rÌbèñy5&FJÃ(êí°&¬,ÚêX$á.=ïïæN$®]Þ½yU0+*§ÔÚ´í6azL(!DÏÝ6ÂNê,Ä5FsíXEó§î_»SG]Úüåt Ô¼'âröÓg!ðSÐ,O¶x><s5ÖRv«N¸¡¿<ý>¼VBñ¤f[ÔÏàø7¿ÂûÊuidÊUS!ÂÕÜÚæòÜíþµüâeüLü'^[¦/d{«oäp¹ÁNî÷޽Oq$Øà-WDsüèXÀÎ}á¾9À̹ÙÎhAÎ ¯P¾ñäK!VIrÏ̯Ín,º~¿IÐ{[D¢=ý%Úîckr¿·_³EÙ]¨g0âk:`vÄÖ</È»HBà4%ª]|;~wÐ=·&;êºÕAr«Á¡GÅòØ)wÂd{Ù BvÞ·3ºàCÔ
Some of the message is decoded correctly, while the rest is a mess. I can, however, not figure out where things go wrong.
I have written a UDF to decode the endcode base64 text in sap pi mapping. But after decoding the xml tags, open and close tags all are getting replaced by > <
Please find below screenshot of the code.
public String Base64Decoder(String EncodedString, Container container) throws StreamTransformationException{//Variable to hold decoded stringString decodedString = null; byte[] decodedBytes = DatatypeConverter.parseBase64Binary(EncodedString);try{//Convert base64 schema to byte arrayreturn new String(decodedBytes,"UTF-8");//Get the string of decoded byte array}catch(Exception e) {}//Export decoded stringreturn decodedString;}
Output after decoding:
<?xml version="1.0" encoding="UTF-8"?><ns0:Log xmlns:ns0="http://world.com/pi/M/Log"><Data><OUTPUT><item><VBELN>0180001027</VBELN><WADAT>00000000</WADAT><VSTEL>1000</VSTEL><KUNNR/><ITEM><YITEM><MATNR>000000000011000082</MATNR><LFIMG>1.0</LFIMG><MEINS>L</MEINS></YITEM></ITEM></item><item><VBELN>0180001233</VBELN><WADAT>00000000</WADAT><VSTEL>1000</VSTEL><KUNNR/><ITEM><YITEM><MATNR>000000000041000000</MATNR><LFIMG>10.0</LFIMG><MEINS>LM</MEINS></YITEM></ITEM></item></OUTPUT></Data></ns0:Log>
The data inside <Data>
tag is decoded text. But as you can see all its tags are replaced. For example, instead of <OUTPUT>
it is printing <OUTPUT>
Can you please let me know what changes should I do in the UDF to avoid this.
Encoded String in Base64:
PE9VVFBVVD48aXRlbT48VkJFTE4+MDE4MDAwMTAyNzwvVkJFTE4+PFdBREFUPjAwMDAwMDAwPC9XQURBVD48VlNURUw+MTAwMDwvVlNURUw+PEtVTk5SLz48SVRFTT48WUlURU0+PE1BVE5SPjAwMDAwMDAwMDAxMTAwMDA4MjwvTUFUTlI+PExGSU1HPjEuMDwvTEZJTUc+PE1FSU5TPkw8L01FSU5TPjwvWUlURU0+PC9JVEVNPjwvaXRlbT48aXRlbT48VkJFTE4+MDE4MDAwMTIzMzwvVkJFTE4+PFdBREFUPjAwMDAwMDAwPC9XQURBVD48VlNURUw+MTAwMDwvVlNURUw+PEtVTk5SLz48SVRFTT48WUlURU0+PE1BVE5SPjAwMDAwMDAwMDA0MTAwMDAwMDwvTUFUTlI+PExGSU1HPjEwLjA8L0xGSU1HPjxNRUlOUz5MTTwvTUVJTlM+PC9ZSVRFTT48L0lURU0+PC9pdGVtPjwvT1VUUFVUPg==
Please note that by viewing our site you agree to our use of cookies (see خلوت for details). You will only see this message once.