as3crypto PEM.readRSAPublicKey returns null
        Posted  
        
            by www.jefferyfernandez.id.au
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by www.jefferyfernandez.id.au
        
        
        
        Published on 2010-04-07T04:35:46Z
        Indexed on 
            2010/04/07
            4:43 UTC
        
        
        Read the original article
        Hit count: 453
        
I am trying to implement a bit of encryption in my Air application while communication with a PHP backend server. For this purpose I am using as3crypto library and I can't read the public key to make the encryption possible. Here is my action script code:
var rsa:RSAKey = PEM.readRSAPublicKey(this.readApplicationFileContents('server.crt')); 
if ( rsa )  
{
    var encodeSource:ByteArray = Hex.toArray(Hex.fromString("Hello World"));  
    var encodeDestination:ByteArray = new ByteArray;  
    var encodeDestination2:ByteArray = new ByteArray;  
    rsa.encrypt(encodeSource, encodeDestination, encodeSource.length)  
    rsa.decrypt(encodeDestination, encodeDestination2, encodeDestination.length);  
    trace(encodeDestination2.toString());  
}  
private function readApplicationFileContents(filePath:String):String  
{   
    var fileObject:File = File.applicationDirectory.resolvePath(filePath);   
    var fileStream:FileStream = new FileStream();   
    fileStream.open(fileObject, FileMode.READ);   
    var fileContents:String = fileStream.readUTFBytes(fileStream.bytesAvailable);   
    return(fileContents);   
} 
readApplicationFileContents function returns the proper certificate contents as a string. But rsa variable always returns null.
It would have been easier if I was able to compile the as3crypto library so I can debug through the source, but I can't get the library to compile and can't find any instructions to do the same. Anyone have a clue what's wrong?
PS. Sorry first time poster and I can't seem to get the syntax highlighting right. Must be Chrome is not working well with the editor.
© Stack Overflow or respective owner