formatPrivateKey() public static method

Returns a private key (adding header & footer if required).
public static formatPrivateKey ( string $key, boolean $heads = true ) : string
$key string A private key
$heads boolean True if we want to include head and footer
return string $rsaKey Formatted private key
Example #1
0
 /**
  * Tests the formatPrivateKey method of the OneLogin_Saml2_Utils
  *
  * @covers OneLogin_Saml2_Utils::formatPrivateKey
  */
 public function testFormatPrivateKey()
 {
     $settingsDir = TEST_ROOT . '/settings/';
     include $settingsDir . 'settings2.php';
     $settings = new OneLogin_Saml2_Settings($settingsInfo);
     $key = $settingsInfo['sp']['privateKey'];
     $this->assertNotContains('-----BEGIN RSA PRIVATE KEY-----', $key);
     $this->assertNotContains('-----END RSA PRIVATE KEY-----', $key);
     $this->assertEquals(strlen($key), 816);
     $formatedKey1 = OneLogin_Saml2_Utils::formatPrivateKey($key);
     $this->assertContains('-----BEGIN RSA PRIVATE KEY-----', $formatedKey1);
     $this->assertContains('-----END RSA PRIVATE KEY-----', $formatedKey1);
     $formatedKey2 = OneLogin_Saml2_Utils::formatPrivateKey($key, true);
     $this->assertEquals($formatedKey1, $formatedKey2);
     $formatedKey3 = OneLogin_Saml2_Utils::formatPrivateKey($key, false);
     $this->assertNotContains('-----BEGIN RSA PRIVATE KEY-----', $formatedKey3);
     $this->assertNotContains('-----END RSA PRIVATE KEY-----', $formatedKey3);
     $this->assertEquals(strlen($key), 816);
 }
Example #2
0
 /**
  * Formats the SP private key.
  */
 public function formatSPKey()
 {
     if (isset($this->_sp['privateKey'])) {
         $this->_sp['privateKey'] = OneLogin_Saml2_Utils::formatPrivateKey($this->_sp['privateKey']);
     }
 }