PHP Secure Communications Library

Jim TerraFrost Wigginton

Abstract

The PHP Secure Communications Library contains LGPL-licensed pure-PHP implementations of arbitrary-precision integers, fully PKCS#1 (v2.1) compliant RSA, DES, 3DES, RC4, Rijndael, AES, SSH-1, SSH-2, and SFTP. This book discusses how to use them.


Table of Contents

1. Introduction
1.1. Who should use phpseclib
1.2. Using phpseclib
2. Math
2.1. Math_BigInteger
2.1.1. Dependencies
2.1.2. The constructor
2.1.3. toString(), toBytes(), toHex() and toBits()
2.1.4. add(), subtract(), multiply() and divide()
2.1.5. powMod() and modInverse()
2.1.6. gcd() and extendedGCD()
2.1.7. abs()
2.1.8. equals() and compare()
2.1.9. setPrecision()
2.1.10. bitwise_and(), bitwise_or(), bitwise_xor() and bitwise_not()
2.1.11. bitwise_rightShift() and bitwise_leftShift()
2.1.12. bitwise_rightRotate() and bitwise_leftRotate()
2.1.13. setRandomGenerator()
2.1.14. isPrime()
2.1.15. random() and randomPrime()
3. Symmetric-key Cryptography
3.1. Introduction
3.1.1. Dependencies
3.1.2. setKey() and setIV()
3.1.3. encrypt() and decrypt()
3.1.4. enableContinuousBuffer() and disableContinuousBuffer()
3.1.5. enablePadding() and disablePadding()
3.1.6. A word of caution about stream ciphers (and CTR / CFB / OFB)
3.2. Crypt_DES
3.2.1. The constructor
3.3. Crypt_TripleDES
3.3.1. The constructor
3.4. Crypt_RC4
3.4.1. The constructor
3.5. Crypt_Rijndael & Crypt_AES
3.5.1. The constructor
3.5.2. AES vs. Rijndael
3.5.3. setKeyLength()
3.5.4. setBlockLength()
3.5.5. Speed Comparisons
4. Miscellaneous Cryptography
4.1. Crypt_Hash
4.1.1. Supported Algorithms and Dependencies
4.1.2. Example
4.2. Crypt_RSA
4.2.1. Dependencies
4.2.2. Examples
4.2.3. createKey()
4.2.4. setPrivateKeyFormat(), setPublicKeyFormat(), loadKey() and setPassword()
4.2.5. setPublicKey() and getPublicKey()
4.2.6. encrypt(), decrypt() and setEncryptionMode()
4.2.7. sign(), verify(), and setSignatureMode()
4.2.8. setHash(), setMGFHash() and setSaltLength()
5. Networking
5.1. Net_SSH
5.1.1. Dependencies
5.1.2. Net_SSH2 Examples
5.1.3. Host Key Verification
5.1.4. read() / write() vs. exec()
5.1.5. sudo with read() / write()
5.1.6. SSH-1's exec() vs. SSH-2's exec()
5.1.7. Successive calls to SSH-2's exec()
5.1.8. Debugging SSH-2
5.2. Net_SFTP
5.2.1. Introduction
5.2.2. Dependencies
5.2.3. Net_SFTP Example
5.2.4. put($remote_file, $data [, $mode])
5.2.5. get($remote_file [, $local_file])
5.2.6. pwd(), chdir(), mkdir() and rmdir()
5.2.7. chmod() and size()
5.2.8. nlist() and rawlist()
5.2.9. stat() and lstat()
5.2.10. delete() and rename()
5.2.11. Debugging SFTP

List of Tables

3.1. AES Speed Comparisons