Index: Business-PayPal-EWP-1.03/EWP.xs
--- Business-PayPal-EWP-1.03/EWP.xs.orig	2010-01-12 15:44:48.000000000 +0100
+++ Business-PayPal-EWP-1.03/EWP.xs	2011-12-25 15:43:55.000000000 +0100
@@ -123,22 +123,32 @@
 
 end:
 	//Free everything
-	if (p7)
-		PKCS7_free(p7);
 	if (bio)
 		BIO_free_all(bio);
-	if (memBio)
-		BIO_free_all(memBio);
 	if (p7bio)
 		BIO_free_all(p7bio);
+	if (memBio)
+		BIO_free_all(memBio);
+	if (p7)
+		PKCS7_free(p7);
 	if (pkey)
 		EVP_PKEY_free(pkey);
 	return ret;
 }
 
+static int ppcb(char *buf, int size, int rwflag, void *passPhrase)
+{
+    size_t n;
 
+    if (passPhrase == NULL)
+        return 0;
+    if ((n = strlen(passPhrase))+1 > size)
+        return 0;
+    strcpy(buf, passPhrase);
+    return n;
+}
 
-char* SignAndEncryptCImpl(char* sCmdTxt, char* keyPath, char* certPath, char* payPalCertPath, bool verbose)
+char* SignAndEncryptCImpl(char* sCmdTxt, char* keyPath, char* certPath, char* payPalCertPath, bool verbose, char *passPhrase)
 {
     BIO     *bio;
     X509    *x509 = NULL;
@@ -177,7 +187,11 @@
         printf("Fatal Error: Failed to open %s\n", keyPath);
         goto end;
     }
-    if ((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)) == NULL)
+    if (passPhrase != NULL && passPhrase[0] != '\0')
+        rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, ppcb, passPhrase);
+    else
+        rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL);
+    if (rsa == NULL)
     {
         printf("Fatal Error: Unable to read RSA key %s\n", keyPath);
         goto end;
@@ -189,8 +203,8 @@
     enc = sign_and_encrypt(sCmdTxt, rsa, x509, PPx509, verbose);
 
 end:
-    if (bio) {
-        BIO_free_all(bio);
+    if (rsa) {
+        RSA_free(rsa);
     }
     if (x509) {
         X509_free(x509);
@@ -198,8 +212,8 @@
     if (PPx509) {
         X509_free(PPx509);
     }
-    if (rsa) {
-        RSA_free(rsa);
+    if (bio) {
+        BIO_free_all(bio);
     }
     return enc;
 }
@@ -210,10 +224,11 @@
 PROTOTYPES: DISABLE
 
 char *
-SignAndEncryptCImpl(sCmdTxt,certPath,keyPath,payPalCertPath,verbose)
+SignAndEncryptCImpl(sCmdTxt,certPath,keyPath,payPalCertPath,verbose,passPhrase)
     char* sCmdTxt
     char* certPath
     char* keyPath
     char* payPalCertPath
     bool  verbose
+    char* passPhrase
    
Index: Business-PayPal-EWP-1.03/lib/Business/PayPal/EWP.pm
--- Business-PayPal-EWP-1.03/lib/Business/PayPal/EWP.pm.orig	2010-01-12 15:46:21.000000000 +0100
+++ Business-PayPal-EWP-1.03/lib/Business/PayPal/EWP.pm	2011-12-25 15:38:28.000000000 +0100
@@ -14,17 +14,10 @@
 XSLoader::load('Business::PayPal::EWP', $VERSION);
 
 sub SignAndEncrypt {
-    my $formdata=shift;
-    my $key=shift;
-    my $cert=shift;
-    my $ppcert=shift;
-
-    # Reformat
-    #$formdata=~s/,/\n/g;
-
-    # Encrypt and sign
-    my $retval = Business::PayPal::EWP::SignAndEncryptCImpl($formdata,$key,$cert,$ppcert,0);
-
+    my ($formdata, $key, $cert, $ppcert, $verbose, $passphrase) = @_;
+    $verbose    = 0  if (not defined $verbose);
+    $passphrase = "" if (not defined $passphrase);
+    my $retval = Business::PayPal::EWP::SignAndEncryptCImpl($formdata,$key,$cert,$ppcert,$verbose,$passphrase);
     return $retval;
 }
 
