Skip to content

codekandis/base64-codec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codekandis/base64-codec

Version License Minimum PHP Version Code Coverage

With the Base64 codec you will be able to encode into and decode from Base64 data in an object oriented way. It wraps PHP's functions base64_encode() and base64_decode().

Index

Installation

Install the latest version with

$ composer require codekandis/base64-codec

How to use

Encoding values

The following examples show how to encode a value.

$value = '8ÇÂ<Ç<ï¯ñ×78B>ïAË¡4Wïc§ÿPîXø4\Êá¡t7?/SµÚ²·x}0¤¯ç»M';

( new Base64Encoder() )
  ->encodeToStandard( $value );
/**
 * OMOHw4I8w4c8w6/Cr8Oxw5c3OEI+w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc/L1PCtcOawrLCt3h9MMKkwq/Dp8K7TQ==
 */
 
( new Base64Encoder() )
  ->encodeToUriSafe( $value );
/**
 * OMOHw4I8w4c8w6_Cr8Oxw5c3OEI-w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc_L1PCtcOawrLCt3h9MMKkwq_Dp8K7TQ
 */

Decoding values

The following examples show how to decode a value.

$standardBase64Value = 'OMOHw4I8w4c8w6/Cr8Oxw5c3OEI+w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc/L1PCtcOawrLCt3h9MMKkwq/Dp8K7TQ==';

( new Base64Decoder() )
  ->decodeFromStandard( $standardBase64Value );
/**
 * 8ÇÂ<Ç<ï¯ñ×78B>ïAË¡4Wïc§ÿPîXø4\Êá¡t7?/SµÚ²·x}0¤¯ç»M
 */ 

$uriSafeBase64Value = 'OMOHw4I8w4c8w6_Cr8Oxw5c3OEI-w69Bw4vCoTRXw69jwqfDv1DDrljDuDRcw4rDocKhdDc_L1PCtcOawrLCt3h9MMKkwq_Dp8K7TQ';

( new Base64Decoder() )
  ->decodeFromUriSafe( $uriSafeBase64Value );
/**
 * 8ÇÂ<Ç<ï¯ñ×78B>ïAË¡4Wïc§ÿPîXø4\Êá¡t7?/SµÚ²·x}0¤¯ç»M
 */

Differences to PHP's Base64 functions

base64_decode() accepts an additional argument $strict to specify if it's forced to decode into an associative array. This argument is omitted in the Base64DecoderInterface while it's intended to always decode in strict mode.

About

`codekandis/base64-codec` is a library providing a codec to encode into and decode from Base64 in an object oriented way.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published