What would be a best Class for base64 encryption/decryption in Action Script?
Adobe has two utils for this - Base64Encoder & Base64Decoder. Both are located in the mx.utils package. Although, I had to track them down here - encoder & decoder.
The usage would be something like:
var bmd:BitmapData = myBitmap.bitmapData;
var ba:ByteArray = bmd.getPixels(new Rectangle(0,0,bmd.width,bmd.height));
var b64:Base64Encoder = new Base64Encoder();
b64.encodeBytes(ba);
trace(b64.toString());
Similarly, 'b64.encode' would encode a String rather than a ByteArray.
Both the encoder and decoder add their respective results to an internal buffer. So, you just have to use 'toString' to return the current buffer.
This one seems to have some legs/supporters: http://garry-lachman.com/2010/04/21/base64-encoding-class-in-actionscript-3/
At this link you will find a good Base64 class:
http://www.sociodox.com/base64.html
blooddy_crypto claims (according to it's benchmark) to have a faster base64 encoder/decoder than the mx.utils one.
Most of the packages that I have seen that include one as a support function use the one that is credited to Steve Webster. I do not know which package this started out in, but it appears in several libraries, including the as3crypto lib on Google Code.
Related
I have recently picked up flixel (I have programmed before, but I have not in a while) and I have come across a problem. I am attempting to create maps, and eventually there will be multiple maps available.
I currently have a .txt file that has information that eventually goes into an array. Then I go from array to map with loadmap. It is maybe a simple way to accomplish this task, and maybe their are better ways (I have not explored all the possibilities with flixel, and if there are any opinions, go ahead and let me know) but it works good for now.
As I have previously said, I am trying to do this with multiple maps. I could do this by using [Embed(source = "")] for each .txt file, but this may end up being annoying. So, here is my question: Is there a possible way Embed a file based upon a variable?
My Map class looks like this:
public function Map(MapSet:String, TileSet:String)
{
super(MapSet, TileSet);
//more stuff
}
Now I have tried:
[Embed(scource="data/MapSets/" + MapSet + ".txt", mimeType = "application/octet-stream")]private var loadedMap:Class
and then I use:
map = new Map("Map1x1", "ForestTiles");
add(map);
Is there a possibility of doing this in a different way? Or maybe I am doing something wrong? All opinions are welcome.
It's beneficial to know what code does when using it.
Embed is a meta tag. It tells the compiler to include a certain file into the .swf file.
That means this does not happen at runtime.
When this embed code is "executed", your variables don't even exist yet.
That's why your code cannot work.
Despite not working, your solution is still valid:
If you find it tedious to generate code, write a program that does this for you. Create/use a program that finds all valid files in the given directory and creates all the embed tags. Run this program before the compiler.
To embed a text file and use as a string, try this:
// create source var TextSource
[Embed(source="textFile.txt",mimeType="application/octet-stream")]
private var TextSource:Class;
var myByteArray:ByteArray = new TextSource();
var myString:String = myByteArray.readUTFBytes(myByteArray.length);
// then use for your function
map = new Map("Map1x1", myString);
I'm working with flex 4 and need to export some pdf files. I'm useing purePDF library for this. Can anyone explain me how to make possible to write romanian characters in pdf files with purePDF -> I need to write characters like ăîşţ, etc.
I look in the wiki documentation of that library but cannot understand enough what I need. Appreciate any help.
Thanks
I'll ask my own question, taking in consideration that it'll be useful for other one.
Note: Taking in account that purepdf is the iText library equivalent from Java, when you encounter any problems and need documentation, you can consult iText documentation for inspiration with purePDF.
So this is what you need to do:
find a suitable "True Type" font that contains your special characters (with "ttf" extension). For me, I found that in the /usr/share/fonts/truetype/*.
copy the *.ttf font file in a directory for use in your application (in my case "assets" directory)
after you find that, you can try it if matches your needs by the following code :
public static const SERIF_NORMAL : String = "FreeSerif.ttf";
//"assets/fonts/FreeSerif.ttf" is the directory where I copied my *.ttf files
[Embed(source="assets/fonts/FreeSerif.ttf", mimeType="application/octet-stream")]
private var serifNormalCls : Class;
private var normalFont : Font;
var bfNormal : BaseFont;
//...
//in youre initialization function :
FontsResourceFactory.getInstance().registerFont(SERIF_NORMAL, new this.serifNormalCls());
bfNormal = BaseFont.createFont(SERIF_NORMAL, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//and when you need to use your the special characters, you will use that font
this.normalFont = new Font(Font.UNDEFINED, 10, Font.UNDEFINED, null, bfNormal);
Cheers!
Several frameworks and languages seem to have lnk file parsers (C#, Java, Python, certainly countless others), to get to their targets, properties, etc. I'd like to know what is the general approach to reading lnk files, if I want to parse the lnk in another language that does not have said feature. Is there a Windows API for this?
There is not an official document from Microsoft describing lnk file format but there are some documents which have description of the format. Here is one of them: Shortcut File Format (.lnk)
As for the API you can use IShellLink Interface
Simply use lnk file parser at J.A.F.A.T. Archive of Forensics Analysis Tools project.
See lnk-parse-1.0.pl at http://jafat.sourceforge.net
There seems no have no dependencies. Syntax is simple and link file becomes a simple text in standard output and to be usable on Linux.
This is an old post, but here is my C# implementation for lnk processing that handles the entire spec, more info and command line tool on this blogspot page.
Using WSH-related components seems the most convenient option to read .lnk files in most languages on a post-XP windows system. You just need access to the COM environment and instantiate the WScript.Shell Component. (remember that on win, references to the Shell usually refer to explorer.exe)
The following snippet, e.g. does the thing on PHP: (PHP 5, using the COM object)
<?php
$wsh=new COM('WScript.Shell'); // the wsh object
// please note $wsh->CreateShortcut method actually
// DOES THE READING, if the file already exists.
$lnk=$wsh->CreateShortcut('./Shortcut.lnk');
echo $lnk->TargetPath,"\n";
This other one, instead, does the same on VBScript:
set sh = WScript.CreateObject("WScript.Shell")
set lnk = sh.CreateShortcut("./Shortcut.lnk")
MsgBox lnk.TargetPath
Most examples in the field are written in VB/VBS, but they translate well on the whole range of languages supporting COM and WSH interaction in a form or another.
This simple tutorial may come handy, as it lists and exemplifies some of the most interesting properties of a .lnk file other than the most important: TargetPath. Those are:
WindowStyle,
Hotkey,
IconLocation,
Description,
WorkingDirectory
here's some C# code using the Shell32 API, from my "ClearRecentLinks" project at https://github.com/jmaton/ClearRecentLinks
To use this your C# project has to reference c:\windows\system32\shell32.dll
string linksPath = "c:\some\folder";
Type shell32Type = Type.GetTypeFromProgID("Shell.Application");
Object shell = Activator.CreateInstance(shell32Type);
Shell32.Folder s32Folder = (Shell32.Folder)shell32Type.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { linksPath });
foreach (Shell32.FolderItem2 item in s32Folder.Items())
{
if (item.IsLink)
{
var link = (Shell32.ShellLinkObject)item.GetLink;
if (link != null && !String.IsNullOrEmpty(link.Target.Path))
{
string linkTarget = link.Target.Path.ToLower();
// do something...
}
}
}
#Giorgi: Actually, there is an official specification of lnk files, at least it is claimed so.
However, for some reason, the link seems to be dead, and after downloading the whole (45 MB) doc package (Application_Services_and_NET_Framework.zip), it appears that it does not include the file MS-SHLLINK.pdf.
But is this really surprising ?
Once you got the file format, shouldn't be too hard to write code to read it.
I've created a simple REST service that serves data as XML. I've managed to enable XML, JS and RSS format but I can not find the way to enable JSON format. Is JS == JSON? Guess not :).
How can I enable this in version 1.2/1.3?
Thx!!
Router::parseExtensions('json');
If you have PHP 5.2 or higher, it ships with JSON encode/decode support. Check the docs here.
You'll probably need to do the encoding/output by hand, but it should be trivial to code.
Bonus points would be to build it as a behavior :)
Edit:
Check out the $javascript->object() method here, it may do what you want.
Quick google search indicates that there are is a json Component for CakePHP. Link to article discussing its use in Cake 1.2: http://www.pagebakers.nl/2007/06/05/using-json-in-cakephp-12/
just add this line of code in your controller or AppController
var $components = array('RequestHandler');
function beforeFilter() {
$this->RequestHandler->setContent('json', 'text/x-json');
}
and run it into internet explorer.
I want to use FileSteam.open() to synchronously read image files from disk. I can then get them into a ByteArray with readBytes(), but I can't find how to get that into BitmapData. I know Image can read it as is, but I need BitmapData.
Any suggestions?
in the package flash.display, use Loader::loadBytes ... that'll give you a Bitmap, and the BitmapData can then be simply accessed through Bitmap::bitmapData ... this makes the whole operation asynchronous, of course ... the only thing you could do, is write a decoder yourself ...
now there is a PNG encoder in AS3, in the as3corelib and i guess there are even others, but probably most people considered it pointless to write a decoder, since flash does this in its own, and also encoding is easier than decoding, because decoding means, you have to implement the whole format ... still, you can give it a shot of course ...
well, hope that helps ...
greetz
back2dos
This library on github has a PNGDecoder that works synchronously. Give it a try:
https://github.com/terrynoya/ASImageLib
From the usage wiki:
var bytes:ByteArray = [PNG bytes];
var bmpData:BitmapData = new PNGDecoder().decode(bytes);
this.addChild(new Bitmap(bmpData));
But I'd imagine using the built-in class would be faster, and while it depends on your use-case, typically when dealing with UI like images, asynchronous is preferred to avoid blocking the UI thread (causing the app to stutter). But there could be some use cases.
It have sense, because FileStream works to manage pure data, and BitmapData works for compile or decompile data.
The way Im about to use, is to read the file in the origin and write a temporary file in the application directory, which may be reached by Loader class without troubles.
Wish me luck!