Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace PragmaRX\Google2FA\Support; use ParagonIE\ConstantTime\Base32 as Paragoni..
Decoded Output download
<?php
namespace PragmaRX\Google2FA\Support; use ParagonIE\ConstantTime\Base32 as ParagonieBase32; use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException; use PragmaRX\Google2FA\Exceptions\InvalidCharactersException; use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException; trait Base32 { protected $enforceGoogleAuthenticatorCompatibility = true; protected function charCountBits($b32) { return strlen($b32) * 8; } public function generateBase32RandomKey($length = 16, $prefix = '') { $secret = $prefix ? $this->toBase32($prefix) : ''; $secret = $this->strPadBase32($secret, $length); $this->validateSecret($secret); return $secret; } public function base32Decode($b32) { $b32 = strtoupper($b32); $this->validateSecret($b32); return ParagonieBase32::decodeUpper($b32); } protected function isCharCountNotAPowerOfTwo($b32) { return (strlen($b32) & strlen($b32) - 1) !== 0; } private function strPadBase32($string, $length) { for ($i = 0; $i < $length; $i++) { $string .= substr(Constants::VALID_FOR_B32_SCRAMBLED, $this->getRandomNumber(), 1); } return $string; } public function toBase32($string) { $encoded = ParagonieBase32::encodeUpper($string); return str_replace("=", '', $encoded); } protected function getRandomNumber($from = 0, $to = 31) { return random_int($from, $to); } protected function validateSecret($b32) { $this->checkForValidCharacters($b32); $this->checkGoogleAuthenticatorCompatibility($b32); $this->checkIsBigEnough($b32); } protected function checkGoogleAuthenticatorCompatibility($b32) { if ($this->enforceGoogleAuthenticatorCompatibility && $this->isCharCountNotAPowerOfTwo($b32)) { throw new IncompatibleWithGoogleAuthenticatorException(); } } protected function checkForValidCharacters($b32) { if (preg_replace("/[^" . Constants::VALID_FOR_B32 . "]/", '', $b32) !== $b32) { throw new InvalidCharactersException(); } } protected function checkIsBigEnough($b32) { if ($this->charCountBits($b32) < 128) { throw new SecretKeyTooShortException(); } } } ?>
Did this file decode correctly?
Original Code
<?php
namespace PragmaRX\Google2FA\Support; use ParagonIE\ConstantTime\Base32 as ParagonieBase32; use PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException; use PragmaRX\Google2FA\Exceptions\InvalidCharactersException; use PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException; trait Base32 { protected $enforceGoogleAuthenticatorCompatibility = true; protected function charCountBits($b32) { return strlen($b32) * 8; } public function generateBase32RandomKey($length = 16, $prefix = '') { $secret = $prefix ? $this->toBase32($prefix) : ''; $secret = $this->strPadBase32($secret, $length); $this->validateSecret($secret); return $secret; } public function base32Decode($b32) { $b32 = strtoupper($b32); $this->validateSecret($b32); return ParagonieBase32::decodeUpper($b32); } protected function isCharCountNotAPowerOfTwo($b32) { return (strlen($b32) & strlen($b32) - 1) !== 0; } private function strPadBase32($string, $length) { for ($i = 0; $i < $length; $i++) { $string .= substr(Constants::VALID_FOR_B32_SCRAMBLED, $this->getRandomNumber(), 1); } return $string; } public function toBase32($string) { $encoded = ParagonieBase32::encodeUpper($string); return str_replace("\x3d", '', $encoded); } protected function getRandomNumber($from = 0, $to = 31) { return random_int($from, $to); } protected function validateSecret($b32) { $this->checkForValidCharacters($b32); $this->checkGoogleAuthenticatorCompatibility($b32); $this->checkIsBigEnough($b32); } protected function checkGoogleAuthenticatorCompatibility($b32) { if ($this->enforceGoogleAuthenticatorCompatibility && $this->isCharCountNotAPowerOfTwo($b32)) { throw new IncompatibleWithGoogleAuthenticatorException(); } } protected function checkForValidCharacters($b32) { if (preg_replace("\57\133\x5e" . Constants::VALID_FOR_B32 . "\135\x2f", '', $b32) !== $b32) { throw new InvalidCharactersException(); } } protected function checkIsBigEnough($b32) { if ($this->charCountBits($b32) < 128) { throw new SecretKeyTooShortException(); } } }
Function Calls
None |
Stats
MD5 | 19cd4a210bb1bac43a7e9cf2c6166b53 |
Eval Count | 0 |
Decode Time | 41 ms |