base64

It is possible to know if a string is encoded in base64?

混江龙づ霸主 提交于 2020-01-13 05:50:10
问题 Simple as that. I'm making an app where the user has to scan a QR code (which basically is a base64 encoded string), is there any way to verify that the string is encoded in base64 before decode and follow the flow of the application? My code would be responsible for that is: func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) { if metadataObjects == nil || metadataObjects.count == 0 {

Invalid length for a Base-64 char array while decryption

烂漫一生 提交于 2020-01-13 03:15:46
问题 I get the following exception in some cases through (decryption) , and i can't recognize exactly the reason : Invalid length for a Base-64 char array My Code : public static string encodeSTROnUrl(string thisEncode) { if (null == thisEncode) return string.Empty; return HttpUtility.UrlEncode(Encrypt(thisEncode)); } // string thisDecode = "3Dn%2bsJJPXprU4%3d"; //this is the value which cause the exception. public static string decodeSTROnUrl(string thisDecode) { return Decrypt(HttpUtility

Invalid length for a Base-64 char array while decryption

我只是一个虾纸丫 提交于 2020-01-13 03:14:16
问题 I get the following exception in some cases through (decryption) , and i can't recognize exactly the reason : Invalid length for a Base-64 char array My Code : public static string encodeSTROnUrl(string thisEncode) { if (null == thisEncode) return string.Empty; return HttpUtility.UrlEncode(Encrypt(thisEncode)); } // string thisDecode = "3Dn%2bsJJPXprU4%3d"; //this is the value which cause the exception. public static string decodeSTROnUrl(string thisDecode) { return Decrypt(HttpUtility

JS逆向 | 原来,大家对于atob和btoa都有误解?不止base64这么简单!

坚强是说给别人听的谎言 提交于 2020-01-13 01:14:16
声明:本文只作学习研究,禁止用于非法用途,否则后果自负,如有侵权,请告知删除,谢谢! 引言  故事是这样的,有位读者朋友需要模拟登录一个网站:  aHR0cDovL3d3dy56bGRzai5jb20v  我进去一看,很简单啊,不就是RSA加密么?  一顿操作猛如虎,把涉及RSA的全部扣下来,然后用Python的base64.b64encode代替 btoa 函数调用即可(由于这里的RSA加密为NoPadding模式,因此对相同明文加密返回的密文都是相同的。RSA的具体相关不在本文讨论范围之内,后面会再出详细教程),结果对比如下:  嗯?为什么结果不一样?检查过代码,确定并没有检查浏览器环境啥的,翻车了…  恰在这时候,又一位读者问了我一个问题,为啥下面这两个也会不一样?有兴趣的可以自行试一下: "IcORUmfDlcOPDsOSwr06fMKgBMKcTQ=="  难道JS的 atob 和 btoa,不等于Python的base64中的 b64decode 和 b64encode 么? 原理分析  想直接看答案的可以跳过此部分。  btoa和atob是window对象的两个函数,其中btoa是binary to ASCII,用于将binary的数据用ASCII码表示,即Base64的编码过程,而atob则是ASCII to binary,用于将ASCII码解析成binary数据

python AES对称加密

隐身守侯 提交于 2020-01-12 16:59:02
1、首先需要安装第三方库   pip install pycryptodome 2、实例代码,亲测可用 # coding:utf-8 import base64 from Crypto.Cipher import AES class USE_AES: """ AES 除了MODE_SIV模式key长度为:32, 48, or 64, 其余key长度为16, 24 or 32 详细见AES内部文档 CBC模式传入iv参数 本例使用常用的ECB模式 """ def __init__(self, key): if len(key) > 32: key = key[:32] self.key = self.to_16(key) def to_16(self, key): """ 转为16倍数的bytes数据 :param key: :return: """ key = bytes(key, encoding="utf8") while len(key) % 16 != 0: key += b'\0' print("to_16") return key # 返回bytes def aes(self): return AES.new(self.key, AES.MODE_ECB) # 初始化加密器 def encrypt(self, text): aes = self.aes() return

how to use php to include an image in a word file?

≡放荡痞女 提交于 2020-01-12 05:24:07
问题 Somebody has asked me to make an app in php that will generate a .doc file with an image and a few tables in it. My first approach was: <?php function data_uri($file, $mime) { $contents = file_get_contents($file); $base64 = base64_encode($contents); return ('data:' . $mime . ';base64,' . $base64); } $file = 'new.doc'; $fh = fopen($file,'w'); $uri = data_uri('pic.png','image/png'); fwrite($fh,'<table border="1"><tr><td><b>something</b></td><td>something else</td></tr><tr><td></td><td></td></tr

Get pixel color of Base64 PNG using javascript?

本秂侑毒 提交于 2020-01-12 03:28:23
问题 I have a base64 encoded PNG. I need to get the color of a pixel using javascript. I assume I'll have to convert it back to a normal PNG. Can anyone point me in the right direction? 回答1: Create an Image object with the base64 image as the source. Then you can draw the image to a canvas and use the getImageData function to get the pixel data. Here's the basic idea (I haven't tested this): var image = new Image(); image.onload = function() { var canvas = document.createElement('canvas'); canvas

python:字符串的加密和编码解码

眉间皱痕 提交于 2020-01-12 02:53:02
文章目录 一:url编码的加密和解码 二:md5加密,不可逆向 三:base64加密和解码 四:unicode编码和解码 一:url编码的加密和解码 1.url编码的加密——–处理为:%CD%F5%B4%F3%B4%B8 def set_url ( password ) : from urllib . parse import quote , unquote utf8_name = quote ( password ) # utf-8 return utf8_name 2.url编码的解码(将的中文乱码符转换为中文),处理形如:%E6%8E%92%EF%E7%AE%97%E6%B3%95 def format_chinese ( str1 ) : from urllib . parse import unquote return unquote ( str1 , encoding = "utf-8" ) 二:md5加密,不可逆向 def set_d5 ( password ) : import hashlib md5 = hashlib . md5 ( ) md5 . update ( password . encode ( ) ) result = md5 . hexdigest ( ) return result 三:base64加密和解码 1.base64编码加密 def

[RoarCTF2019]黄金6年

余生颓废 提交于 2020-01-12 01:45:11
嘶吼CTF的杂项题 这道题目比较简单 下载之后是一个mp4文件,黄金六年,害,亲爱的热爱的里面的梗 使用010 Editor打开视频文件,发现最下面有base64编码 UmFyIRoHAQAzkrXlCgEFBgAFAQGAgADh7ek5VQIDPLAABKEAIEvsUpGAAwAIZmxhZy50eHQwAQAD Dx43HyOdLMGWfCE9WEsBZprAJQoBSVlWkJNS9TP5du2kyJ275JzsNo29BnSZCgMC3h+UFV9p1QEf JkBPPR6MrYwXmsMCMz67DN/k5u1NYw9ga53a83/B/t2G9FkG/IITuR+9gIvr/LEdd1ZRAwUEAA== 在线解码一下 可以看出来是Rar文件,编写python脚本将其输出 import base64 code="UmFyIRoHAQAzkrXlCgEFBgAFAQGAgADh7ek5VQIDPLAABKEAIEvsUpGAAwAIZmxhZy50eHQwAQADDx43HyOdLMGWfCE9WEsBZprAJQoBSVlWkJNS9TP5du2kyJ275JzsNo29BnSZCgMC3h+UFV9p1QEfJkBPPR6MrYwXmsMCMz67DN/k5u1NYw9ga53a83/B/t2G9FkG/IITuR+9gIvr/LEdd1ZRAwUEAA==" r

How to convert string to base64 byte array, would this be valid?

自作多情 提交于 2020-01-11 21:53:26
问题 I'm trying to write a function that converts a string to a base64 byte array. I've tried with this approach: public byte[] stringToBase64ByteArray(String input) { byte[] ret = System.Text.Encoding.Unicode.GetBytes(input); string s = Convert.ToBase64String(input); ret = System.Text.Encoding.Unicode.GetBytes(s); return ret; } Would this function produce a valid result (provided that the string is in unicode)? Thanks! 回答1: Looks okay, although the approach is strange. But use Encoding.ASCII