1--TEST-- 2openssl_pkey_new() basic usage tests 3--EXTENSIONS-- 4openssl 5--SKIPIF-- 6<?php 7if (!defined("OPENSSL_KEYTYPE_DSA")) die("skip DSA disabled"); 8?> 9--FILE-- 10<?php 11function openssl_pkey_test_cmp($expected, $bin_key) { 12 var_dump(strcasecmp(ltrim($expected, '0'), bin2hex($bin_key))); 13} 14 15// RSA 16$nhex = "BBF82F090682CE9C2338AC2B9DA871F7368D07EED41043A440D6B6F07454F51F" . 17 "B8DFBAAF035C02AB61EA48CEEB6FCD4876ED520D60E1EC4619719D8A5B8B807F" . 18 "AFB8E0A3DFC737723EE6B4B7D93A2584EE6A649D060953748834B2454598394E" . 19 "E0AAB12D7B61A51F527A9A41F6C1687FE2537298CA2A8F5946F8E5FD091DBDCB"; 20 21$ehex = "11"; 22$dhex = "A5DAFC5341FAF289C4B988DB30C1CDF83F31251E0668B42784813801579641B2" . 23 "9410B3C7998D6BC465745E5C392669D6870DA2C082A939E37FDCB82EC93EDAC9" . 24 "7FF3AD5950ACCFBC111C76F1A9529444E56AAF68C56C092CD38DC3BEF5D20A93" . 25 "9926ED4F74A13EDDFBE1A1CECC4894AF9428C2B7B8883FE4463A4BC85B1CB3C1"; 26 27$phex = "EECFAE81B1B9B3C908810B10A1B5600199EB9F44AEF4FDA493B81A9E3D84F632" . 28 "124EF0236E5D1E3B7E28FAE7AA040A2D5B252176459D1F397541BA2A58FB6599"; 29 30$qhex = "C97FB1F027F453F6341233EAAAD1D9353F6C42D08866B1D05A0F2035028B9D86" . 31 "9840B41666B42E92EA0DA3B43204B5CFCE3352524D0416A5A441E700AF461503"; 32 33$dphex = "11"; 34$dqhex = "11"; 35$qinvhex = "b06c4fdabb6301198d265bdbae9423b380f271f73453885093077fcd39e2119f" . 36 "c98632154f5883b167a967bf402b4e9e2e0f9656e698ea3666edfb25798039f7"; 37 38$rsa= openssl_pkey_new(array( 39 'rsa' => array( 40 'n' => hex2bin($nhex), 41 'e' => hex2bin($ehex), 42 'd' => hex2bin($dhex), 43 'p' => hex2bin($phex), 44 'q' => hex2bin($qhex), 45 'dmp1' => hex2bin($dphex), 46 'dmq1' => hex2bin($dqhex), 47 'iqmp' => hex2bin($qinvhex), 48 ) 49)); 50$details = openssl_pkey_get_details($rsa); 51$rsa_details = $details['rsa']; 52openssl_pkey_test_cmp($nhex, $rsa_details['n']); 53openssl_pkey_test_cmp($ehex, $rsa_details['e']); 54openssl_pkey_test_cmp($dhex, $rsa_details['d']); 55openssl_pkey_test_cmp($phex, $rsa_details['p']); 56openssl_pkey_test_cmp($qhex, $rsa_details['q']); 57openssl_pkey_test_cmp($dphex, $rsa_details['dmp1']); 58openssl_pkey_test_cmp($dqhex, $rsa_details['dmq1']); 59openssl_pkey_test_cmp($qinvhex, $rsa_details['iqmp']); 60echo "\n"; 61 62// DSA 63$phex = '00f8000ae45b2dacb47dd977d58b719d097bdf07cb2c17660ad898518c08' . 64 '1a61659a16daadfaa406a0a994c743df5eda07e36bd0adcad921b77432ff' . 65 '24ccc31e782d647e66768122b578857e9293df78387dc8b44af2a4a3f305' . 66 '1f236b1000a3e31da489c6681b0031f7ec37c2e1091bdb698e7660f135b6' . 67 '996def90090303b7ad'; 68 69$qhex = '009b3734fc9f7a4a9d6437ec314e0a78c2889af64b'; 70 71$ghex = '00b320300a0bc55b8f0ec6edc218e2185250f38fbb8291db8a89227f6e41' . 72 '00d47d6ccb9c7d42fc43280ecc2ed386e81ff65bc5d6a2ae78db7372f5dc' . 73 'f780f4558e7ed3dd0c96a1b40727ac56c5165aed700a3b63997893a1fb21' . 74 '4e882221f0dd9604820dc34e2725dd6901c93e0ca56f6d76d495c332edc5' . 75 'b81747c4c447a941f3'; 76$dsa = openssl_pkey_new(array( 77 'dsa' => array( 78 'p' => hex2bin($phex), 79 'q' => hex2bin($qhex), 80 'g' => hex2bin($ghex) 81 ) 82)); 83$details = openssl_pkey_get_details($dsa); 84$dsa_details = $details['dsa']; 85openssl_pkey_test_cmp($phex, $dsa_details['p']); 86openssl_pkey_test_cmp($qhex, $dsa_details['q']); 87openssl_pkey_test_cmp($ghex, $dsa_details['g']); 88var_dump(strlen($dsa_details['priv_key'])); 89var_dump(strlen($dsa_details['pub_key'])); 90 91// DH 92$phex = 'dcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61e' . 93 'f75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d268370557' . 94 '7d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e382' . 95 '6634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22c583ab'; 96 97$dh_details = array('p' => $phex, 'g' => '2'); 98$dh = openssl_pkey_new(array( 99 'dh'=> array('p' => hex2bin($phex), 'g' => '2')) 100); 101$details = openssl_pkey_get_details($dh); 102$dh_details = $details['dh']; 103openssl_pkey_test_cmp($phex, $dh_details['p']); 104var_dump($dh_details['g']); 105var_dump(strlen($dh_details['pub_key'])); 106var_dump(strlen($dh_details['priv_key'])); 107?> 108--EXPECTF-- 109int(0) 110int(0) 111int(0) 112int(0) 113int(0) 114int(0) 115int(0) 116int(0) 117 118int(0) 119int(0) 120int(0) 121int(%d) 122int(%d) 123int(0) 124string(1) "2" 125int(%d) 126int(%d) 127