phpseclib

Encrypting in Java and decrypting in PHP with Phpseclib

随声附和 提交于 2019-12-04 15:59:26
问题 Edit 2: Problem has been solved. I didn't understand how the loadkey function in php was supposed to work and I mistakenly assumed it would read a key file (it does not). The solution was to read the contents of the file into a variable and then load the variable with loadkey. Edit: The problem seems to be with the key. I realized that loadkey is returning false, indicating that it was unable to read the key. Could there be a difference in the formats accepted by phpseclib and the keys

JAVA RSA Decryption not working, throws InvalidKeySpecException

牧云@^-^@ 提交于 2019-12-04 14:48:01
问题 I used phpseclib to generate RSA public and private key. $rsa = new Crypt_RSA(); $rsa->setHash('sha1'); $rsa->setMGFHash('sha1'); $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP); $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1); $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1); extract($rsa->createKey(2048)); Then i used these two keys in my android app to encrypt/decrypt data. public static final String publicKey = "MIIBIjANBgk......DAQAB"; public static final String

How to RSA verify a signature in java that was generated in php

旧巷老猫 提交于 2019-12-04 14:41:56
问题 We are using phpseclib for Public key signing of data and android java is used for Public key verification. But it repeatedtly failed. PHP Code For generating keys and signing by private key include_once("phpseclib/autoload.php"); function getKeys($keysize=2048){ $rsa = new Crypt_RSA(); //$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH); //$rsa->setPublicKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1); $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS8); $rsa->setPublicKeyFormat

Integrate phpseclib into Laravel 5

妖精的绣舞 提交于 2019-12-04 14:23:10
i am currently migrating my Project from Laravel 4 to Laravel 5, i am still a novice user of Laravel and OOP as well but everything went smoothly so far. However, in my L4 project I use the phpseclib for generating SSH keys which I imported in the following way: MyController.php ... include('../app/libs/phpseclib0.3.10/Crypt/RSA.php'); $rsa = new Crypt_RSA(); ... which does not seems to work anymore: syntax error, unexpected 'if' (T_IF), expecting identifier (T_STRING) .../app/libs/phpseclib0.3.10/Crypt/RSA.php /** * Include Crypt_Random */ // the class_exists() will only be called if the

phpseclib/jsbn: encrypt with public key in PHP, decrypt with private key in jsbn

…衆ロ難τιáo~ 提交于 2019-12-04 12:30:43
I can successfully generate a public/private keypair using jsbn on the client side. Encrypting and decrypting client side with these keys is fine. I can also transmit that public key to the server and store it in MySQL via PHP. I cannot encrypt something in PHP using the jsbn public key, and then decrypt it client side using the jsbn private key. // attempting to encrypt in PHP using the jsbn public key. // (this public key came from jsbn client side) $jsbn_public_key =

JAVA RSA Decryption not working, throws InvalidKeySpecException

你离开我真会死。 提交于 2019-12-03 10:13:46
I used phpseclib to generate RSA public and private key. $rsa = new Crypt_RSA(); $rsa->setHash('sha1'); $rsa->setMGFHash('sha1'); $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP); $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1); $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1); extract($rsa->createKey(2048)); Then i used these two keys in my android app to encrypt/decrypt data. public static final String publicKey = "MIIBIjANBgk......DAQAB"; public static final String privateKey = "MIIEpAI......Zh+0bQ=="; I can encrypt data in JAVA with public key and decrypt that data in

How to RSA verify a signature in java that was generated in php

天大地大妈咪最大 提交于 2019-12-03 09:14:23
We are using phpseclib for Public key signing of data and android java is used for Public key verification. But it repeatedtly failed. PHP Code For generating keys and signing by private key include_once("phpseclib/autoload.php"); function getKeys($keysize=2048){ $rsa = new Crypt_RSA(); //$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH); //$rsa->setPublicKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1); $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS8); $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1); $d = $rsa->createKey($keysize); return array("publickey"=>$d['publickey'],

Decrypt data using RSA between PHP and Java Android issue

我的梦境 提交于 2019-12-03 09:11:13
I am using a PHP server to encrypt some data and then decrypt it to an Android device. But when I try to decrypt it on the Android device side, I get the following error : javax.crypto.BadPaddingException: error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block type is not 02 When I am on Cipher.getInstance("RSA/ECB/PKCS1Padding"); I am encrypting the value on a PHP server using PHPSeclips Library (last github version at this date) and signing as well. This part does actually works because already used to be decoded on a Javacard program so the error does not actually belongs here.

PHP decrypting data with RSA Private Key

我的梦境 提交于 2019-12-02 21:19:05
问题 I have a program that encrypts passwords using a c# rsa public key which outputs a byte array. In order for me to transport it easily and maintain data I am converting the bytes directly to a Hex string. Now this is where I am having issue. I send the post data to my script and am now unsure what to convert it to and how to decrypt it. I am attempting to use http://phpseclib.sourceforge.net/ which I was pointed to by this post RSA decryption using private key The documentation on this is very

Files not uploading to remote server with Net_SFTP

久未见 提交于 2019-12-02 14:22:56
问题 I have the following class for uploading files in a directory, however, the first directory that should be created is getting set up as 'File' rather then a 'File Folder'. Because of that, the items that should be uploaded are not uploading properly. I'm not sure if I am missing a step or not or if I set this up incorrectly. include 'Net/SFTP.php'; class SFTPConnection { private $sftp; public function __construct($host, $username, $password) { $this->sftp = new Net_SFTP($host); if (!$this-