如何保存加密图像并稍后读取以获取原始图像在javascript中

时间:2016-04-20 14:11:35

标签: javascript encryption

我有一个加密图像,其内容的格式为

var image='p%ì3T!0!!0!-Ùg j\½+ÚïMür{-xüPOgm!45!!45!¬ÚñþÍ-¶ÎyP¢Ñàî!33!¢z·Ã-¹Çó̹ÅÖ{ôønÀ~-±µü¹«¬Ìò!34!d^ãø-h!0!æSkI^%»¯z¹-/¥ÖÀÇG¾sÂú-õadÑ7it4x±(¸ë-±ÝÅ){!45!Xº»±uƼ-¥®bÙeJû?PMú-%Ò!0!7!13!n5ZÙL«C-';

我正在使用

将图像保存到磁盘上
   function upload(image) {
   var b64Data= image.replace(/^data:image\/\w+;base64,/, '');
var blob = b64toBlob(b64Data, 'image');

saveAs(blob, "hello world.jpg");

}
function b64toBlob(b64Data1, contentType, sliceSize) {
  contentType = contentType || '';
  sliceSize = sliceSize || 512;
  console.log('log2...');

  console.log(b64Data1);

  var byteCharacters = atob(b64Data1);
  var byteArrays = [];

  for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
    var slice = byteCharacters.slice(offset, offset + sliceSize);

    var byteNumbers = new Array(slice.length);
    for (var i = 0; i < slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i);
    }

    var byteArray = new Uint8Array(byteNumbers);

    byteArrays.push(byteArray);
  }

  var blob = new Blob(byteArrays, {type: contentType});
  return blob;
}

我正在使用

阅读它
 window.onload = function(){

//Check File API support
if(window.File && window.FileList && window.FileReader)
{
    var filesInput = document.getElementById("files");
    //console.log(filesInput);
    filesInput.addEventListener("change", function(event){

        var files = event.target.files; //FileList object
        console.log(files.length);
        var output1 = document.getElementById("result1");
        //console.log(output3);
      //  console.log(files);

        for(var i = 0; i< files.length; i++)
        {
            var file = files[i];
          //  console.log(file);

            //Only pics
            if(!file.type.match('image'))
              continue;

            var picReader = new FileReader();

            picReader.addEventListener("load",function(event){

                var picFile = event.target;

                var div1 = document.createElement("div1");

                div1.innerHTML = "<img class='thumbnail' src='" + picFile.result + "'" +
                        "title='" + picFile.name + "'/>";



            });

             //Read the image
            picReader.readAsDataURL(file);
        }                               

    });
}
else
{
    console.log("Your browser does not support File API");
}
  }

接下来,我正在解密加密数据并使用相同的第一个功能保存...但我无法获得相同的图像....当我不将密码保存到密码时,它工作正常一个文件,但直接发送到解密功能...任何人都可以建议我以什么编码格式保存密码以保留其原始格式,以便我得到相同的图像

0 个答案:

没有答案