public static NDB.Post[] Unpack(Image container, string key) //this Unpack using Image from RAM, as parameter. { try { //Console.WriteLine("Start read hidden bytes"); var encrypted = new PngStegoUtil().ReadHiddenBytesFromPng(container); //here can be catch //Console.WriteLine("readhiddenbytesFromPNG.........."); var decrypted = ByteEncryptionUtil.DecryptSalsa20(encrypted, key); //here can be catch //Console.WriteLine("decrypted..........."); var nposts = NanoPostPackUtil.Unpack(decrypted); //here can be catch //Console.WriteLine("nposts..........."); var posts = nposts.Select( //here can be catch np => new NDB.Post { replyto = np.SerializedString().Substring(0, 32), message = Convert.ToBase64String(Encoding.UTF8.GetBytes(np.SerializedString().Substring(32))) }).ToArray(); //Console.WriteLine("posts..........."); Validate(posts); //AND HERE reason of for lagging containers //Console.WriteLine("Validate..........."); return(posts); } catch // (Exception e) fix compile warning { //Console.WriteLine("Unpack catch"); //here can be catch. return(new NDB.Post[0]); } }
//GET-query to http://127.0.0.1:7346/api/run-nbpack/-u|upload%2FMORE-secrets-inside.png|nano3|upload%2Fposts.json //or POST-query to http://127.0.0.1:7346/api/run-nbpack/ with four parameters - saving the JSON-file. //dataURL of PNG is supporting in containerPath. private static void Unpack(string containerPath, string key, string outputPath) { try { var encrypted = new PngStegoUtil().ReadHiddenBytesFromPng(containerPath); var decrypted = ByteEncryptionUtil.DecryptSalsa20(encrypted, key); var nposts = NanoPostPackUtil.Unpack(decrypted); var posts = nposts.Select( np => new NDB.Post { replyto = np.SerializedString().Substring(0, 32), message = Convert.ToBase64String(Encoding.UTF8.GetBytes(np.SerializedString().Substring(32))) }).ToArray(); Validate(posts); //from the sources of client 3.1 for (int i = 0; i < posts.Length; i++) { posts[i].message = NDB.PostsValidator.FromB64(posts[i].message); } var result = JsonConvert.SerializeObject(posts, Formatting.Indented); File.WriteAllText(outputPath, result); } catch { var posts = new Posts(); posts.posts = new Post[0]; var result = JsonConvert.SerializeObject(posts); File.WriteAllText(outputPath, result); } return; }
//GET-query to http://127.0.0.1:7346/api/run-nbpack/-u|upload%2FMORE-secrets-inside.png|nano3 //or POST-query to http://127.0.0.1:7346/api/run-nbpack/ with three two parameters - return JSON. //dataURL of PNG is supporting in containerPath. public static NDB.Post[] Unpack(string containerPath, string key) //containerPath - pathway to container, as file { try { //Console.WriteLine("Start read hidden bytes"); var encrypted = new PngStegoUtil().ReadHiddenBytesFromPng(containerPath); //Console.WriteLine("readhiddenbytesFromPNG.........."); var decrypted = ByteEncryptionUtil.DecryptSalsa20(encrypted, key); //here is reason of catch for some files //Console.WriteLine("decrypted..........."); var nposts = NanoPostPackUtil.Unpack(decrypted); //or here //Console.WriteLine("nposts..........."); var posts = nposts.Select( //or here np => new NDB.Post { replyto = np.SerializedString().Substring(0, 32), message = Convert.ToBase64String(Encoding.UTF8.GetBytes(np.SerializedString().Substring(32))) }).ToArray(); //Console.WriteLine("posts..........."); Validate(posts); //in the most cases this not working, then catch //Console.WriteLine("Validate..........."); return(posts); } catch // (Exception e) //fix compile warning { Console.WriteLine("Unpack catch: " + ( (containerPath.IndexOf("data:") != -1 && containerPath.IndexOf("base64,") != -1 && nbpack.NBPackMain.IsBase64Encoded(containerPath.Split(',')[1]) ) ? containerPath.Substring(0, 40) + "..." : containerPath ) ); //here catch for some files. return(new NDB.Post[0]); } }