Crypt_RSA with a public key from .NET framework

From: Date: Sat, 14 Jan 2006 09:34:27 +0000
Subject: Crypt_RSA with a public key from .NET framework
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22529@lists.php.net to get a copy of this message
Hello, I try to implement some data communication between a .NET application and a PHP script. PEAR's Crypt_RSA package is to add RSA support for PHP side. I've generated a public and a private key with .NET application and transferred the public key in XML format to the server. For some reason, I can't get the encryption/decryption to work correctly. In which format should I input the public key to Crypt_RSA object? You will see my current try below: <? // String to be encrypted $clear_data = 'Foobar'; // XML Exported RSA public key (from .NET) $rsaxml = '<RSAKeyValue><Modulus>zCcMoodN4m7mtdrxr0WHdo4KiLxqqzafB4xbEAJrDL+fKlwN5Fj1LOZJIJlEXnTAaFy2QcNjZ1UJeFihnE5LX7PgZnd0XP1qSYKDu2Hh/UOBE/HsrL+fHCVrK5CShROrB38B4SCsxITP8tsYAx4vHIrDPjltKDDCw4xUX4p01CoSgbaLdNSMlJ6PoO+ROqBvLghTwAAT5OJtycLNulX+/VBqtCUh7LWcWNs0GKncuG3PI0rfmZedpkbUGYNxAJzn45RgL+ho/oWgofnaQvZa2VV68ZF5WE/dBw/JMNzBDc/WtXzw4kvDBL54dEv6PZFVlqqqNeGZJIEoBmy4w9WytQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>'; ereg("<RSAKeyValue><Modulus>(.*)</Modulus><Exponent>(.*)</Exponent></RSAKeyValue>", $rsaxml, $regs); $modulus = base64_decode($regs[1]); $exp = hexdec($regs[2]); $key = new Crypt_RSA_Key($modulus, $exp, 'public'); $crypt = new Crypt_RSA; // Encrypt the data $enc_data = $crypt->encrypt($clear_data, $key); ?> Thanks, Ville

« previous php.pear.general (#22529) next »