A simple and powerful PHP library for working with WinSCP password encryption and session management.
- Password Encryption/Decryption: Encrypt and decrypt passwords using WinSCP's proprietary algorithm
- Format Conversion: Convert between JSON and WinSCP INI formats
- Session Management: Handle WinSCP session configurations with support for categories and nested structures
- Production Ready: Tested and optimized for production environments
Simply download the WinSCP.php
file and include it in your project:
require_once 'WinSCP.php';
// Encrypt a password
$encrypted = WinSCP::encryptPassword('username', 'hostname.com', 'plaintext_password');
echo $encrypted; // A35C4F5BC9639256174DAC2E3333286D726E726F72682C3D2F...
// Decrypt a password
$decrypted = WinSCP::decryptPassword('username', 'hostname.com', $encrypted);
echo $decrypted; // plaintext_password
// Convert JSON configuration to WinSCP INI format
$iniContent = WinSCP::convertJsonToIni('sessions.json');
file_put_contents('sessions.ini', $iniContent);
// Or save directly to file
WinSCP::convertJsonToIni('sessions.json', 'output.ini');
// Convert WinSCP INI to JSON format
$jsonData = WinSCP::convertIniToJson('sessions.ini');
file_put_contents('sessions.json', json_encode($jsonData, JSON_PRETTY_PRINT));
// Or save directly to file
WinSCP::convertIniToJson('sessions.ini', 'output.json');
The library expects JSON files with the following structure:
{
"sessions": [
{
"name": "production-server",
"hostname": "prod.example.com",
"port": 22,
"username": "root",
"password": "secure_password"
},
{
"category": "Development",
"hosts": [
{
"name": "dev-server",
"hostname": "dev.example.com",
"port": 2222,
"username": "developer",
"password": "dev_password"
}
]
}
]
}
- WinSCP Compatible: Passwords encrypted with this library work directly in WinSCP
- Secure Algorithm: Uses WinSCP's proprietary encryption algorithm
- Random Padding: Includes random padding for additional security
- Bidirectional: Can encrypt new passwords and decrypt existing WinSCP passwords
Run the included test file to verify functionality:
php temp/test.php
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please open an issue on GitHub.
Made with ❤️ by AriaData