Subversion Repositories cheapmusic

Rev

Rev 9 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9 Rev 10
Line 36... Line 36...
36
    /**
36
    /**
37
     * Create a Cryptor singleton instance
37
     * Create a Cryptor singleton instance
38
     * @param array $cryptConfig The cipher algorithm, the hash algorithm and the key.
38
     * @param array $cryptConfig The cipher algorithm, the hash algorithm and the key.
39
     * @param [type] $fmt         Optional override for the output encoding. One of FORMAT_RAW, FORMAT_B64 or FORMAT_HEX. Default: FORMAT_B64.
39
     * @param [type] $fmt         Optional override for the output encoding. One of FORMAT_RAW, FORMAT_B64 or FORMAT_HEX. Default: FORMAT_B64.
40
     */
40
     */
41
    public function getInstance($cryptorConfig = null, $fmt = Cryptor::FORMAT_B64)
41
    public static function getInstance($cryptorConfig = null, $fmt = Cryptor::FORMAT_B64)
42
    {
42
    {
43
        if (is_null(self::$instance)){
43
        if (is_null(self::$instance)){
44
            self::$instance = new self();
44
            self::$instance = new self();
45
            if (!extension_loaded("openssl")) {
45
            if (!extension_loaded("openssl")) {
46
                self::$hasOpenSSL = false;    
46
                self::$hasOpenSSL = false;    
Line 92... Line 92...
92
     * @param  string $in  String to encrypt.
92
     * @param  string $in  String to encrypt.
93
     * @param  string $key Optional encryption key.
93
     * @param  string $key Optional encryption key.
94
     * @param  int $fmt Optional override for the output encoding. One of FORMAT_RAW, FORMAT_B64 or FORMAT_HEX.
94
     * @param  int $fmt Optional override for the output encoding. One of FORMAT_RAW, FORMAT_B64 or FORMAT_HEX.
95
     * @return string      The encrypted string.
95
     * @return string      The encrypted string.
96
     */
96
     */
97
    public function encryptString($in, $key = null, $fmt = null)
97
    public static function encryptString($in, $key = null, $fmt = null)
98
    {
98
    {
99
        if (!self::$hasOpenSSL) {
99
        if (!self::$hasOpenSSL) {
100
            return base64_encode($in);
100
            return base64_encode($in);
101
        }
101
        }
102
        if ($fmt === null)
102
        if ($fmt === null)
Line 139... Line 139...
139
     * @param  string $in  String to decrypt.
139
     * @param  string $in  String to decrypt.
140
     * @param  string $key Optional decryption key.
140
     * @param  string $key Optional decryption key.
141
     * @param  int $fmt Optional override for the input encoding. One of FORMAT_RAW, FORMAT_B64 or FORMAT_HEX.
141
     * @param  int $fmt Optional override for the input encoding. One of FORMAT_RAW, FORMAT_B64 or FORMAT_HEX.
142
     * @return string      The decrypted string.
142
     * @return string      The decrypted string.
143
     */
143
     */
144
    public function decryptString($in, $key = null, $fmt = null)
144
    public static function decryptString($in, $key = null, $fmt = null)
145
    {
145
    {
146
        if (!self::$hasOpenSSL) {
146
        if (!self::$hasOpenSSL) {
147
            return base64_decode($in);
147
            return base64_decode($in);
148
        }
148
        }
149
        if ($fmt === null)
149
        if ($fmt === null)