1 | <?php |
||
14 | abstract class Crypto |
||
15 | { |
||
16 | /** |
||
17 | * Sign data with given algorithm using given private key. |
||
18 | * |
||
19 | * @param string $data Data to sign |
||
20 | * @param PrivateKeyInfo $privkey_info Private key |
||
21 | * @param SignatureAlgorithmIdentifier $algo Signature algorithm |
||
22 | * @return Signature |
||
23 | */ |
||
24 | abstract public function sign($data, PrivateKeyInfo $privkey_info, |
||
26 | |||
27 | /** |
||
28 | * Verify signature with given algorithm using given public key. |
||
29 | * |
||
30 | * @param string $data Data to verify |
||
31 | * @param Signature $signature Signature |
||
32 | * @param PublicKeyInfo $pubkey_info Public key |
||
33 | * @param SignatureAlgorithmIdentifier $algo Signature algorithm |
||
34 | * @return bool True if signature matches |
||
35 | */ |
||
36 | abstract public function verify($data, Signature $signature, |
||
38 | |||
39 | /** |
||
40 | * Encrypt data with given algorithm using given key. |
||
41 | * |
||
42 | * Padding must be added by the caller. Initialization vector is |
||
43 | * taken from the algorithm identifier if available. |
||
44 | * |
||
45 | * @param string $data Plaintext |
||
46 | * @param string $key Encryption key |
||
47 | * @param CipherAlgorithmIdentifier $algo Encryption algorithm |
||
48 | * @return string Ciphertext |
||
49 | */ |
||
50 | abstract public function encrypt($data, $key, CipherAlgorithmIdentifier $algo); |
||
51 | |||
52 | /** |
||
53 | * Decrypt data with given algorithm using given key. |
||
54 | * |
||
55 | * Possible padding is not removed and must be handled by the caller. |
||
56 | * Initialization vector is taken from the algorithm identifier if |
||
57 | * available. |
||
58 | * |
||
59 | * @param string $data Ciphertext |
||
60 | * @param string $key Encryption key |
||
61 | * @param CipherAlgorithmIdentifier $algo Encryption algorithm |
||
62 | * @return string Plaintext |
||
63 | */ |
||
64 | abstract public function decrypt($data, $key, CipherAlgorithmIdentifier $algo); |
||
65 | |||
66 | /** |
||
67 | * Get default supported crypto implementation. |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | 1 | public static function getDefault() |
|
80 | } |
||
81 |