DefuseCryptoKey

The WooCommerce Germanized Defuse Crypto Key class.

Defined (1)

The class is defined in the following location(s).

/includes/gateways/direct-debit/libraries/php-encryption/Key.php  
  1. final class Key 
  2. const KEY_CURRENT_VERSION = "\xDE\xF0\x00\x00"; 
  3. const KEY_BYTE_SIZE = 32; 
  4.  
  5. private $key_bytes = null; 
  6.  
  7. /** 
  8. * Creates new random key. 
  9. * @throws Defuse\Crypto\Exception\EnvironmentIsBrokenException 
  10. * @return Defuse\Crypto\Key 
  11. */ 
  12. public static function createNewRandomKey() 
  13. return new Key(Core::secureRandom(self::KEY_BYTE_SIZE)); 
  14.  
  15. /** 
  16. * Loads a Key from its encoded form. 
  17. * @param string $savedKeyString 
  18. * @throws \Defuse\Crypto\Exception\BadFormatException 
  19. * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException 
  20. * @return \Defuse\Crypto\Key 
  21. */ 
  22. public static function loadFromAsciiSafeString($saved_key_string) 
  23. $key_bytes = Encoding::loadBytesFromChecksummedAsciiSafeString(self::KEY_CURRENT_VERSION, $saved_key_string); 
  24. return new Key($key_bytes); 
  25.  
  26. /** 
  27. * Encodes the Key into a string of printable ASCII characters. 
  28. * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException 
  29. * @return string 
  30. */ 
  31. public function saveToAsciiSafeString() 
  32. return Encoding::saveBytesToChecksummedAsciiSafeString( 
  33. self::KEY_CURRENT_VERSION,  
  34. $this->key_bytes 
  35. ); 
  36.  
  37. /** 
  38. * Gets the raw bytes of the key. 
  39. * @return string 
  40. */ 
  41. public function getRawBytes() 
  42. return $this->key_bytes; 
  43.  
  44. /** 
  45. * Constructs a new Key object from a string of raw bytes. 
  46. * @param string $bytes 
  47. * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException 
  48. */ 
  49. private function __construct($bytes) 
  50. if (Core::ourStrlen($bytes) !== self::KEY_BYTE_SIZE) { 
  51. throw new Ex\EnvironmentIsBrokenException( 
  52. 'Bad key length.' 
  53. ); 
  54. $this->key_bytes = $bytes; 
  55.  
  56. /** 
  57. * INTERNAL USE ONLY: Constructs a Key object from a string of raw bytes. 
  58. * @param $bytes 
  59. * @return \Defuse\Crypto\Key 
  60. * @internal 
  61. */ 
  62. public static function loadFromRawBytesForTestingPurposesOnlyInsecure($bytes) 
  63. return new Key($bytes);