base64上传
@datetime 2017-11-01T14:46:58+0800
@author   韩文博
@param    string $base64_content
@throws \Exception
767332
public function base64Upload( string $base64_content ) : Image
	{
		$this->file = $base64_content;

		// data:image/png;base64,
		list( $head, $content ) = explode( ",", $this->file );
		$this->mediaType  = str_replace( ';base64', '', str_replace( 'data:', '', $head ) );
		$this->ext        = strtolower( explode( '/', $this->mediaType )[1] ); // todo 单独来个方法设置
		$this->originName = "base64";
		if( !in_array( $this->ext, $this->allowFileType ) ){
			throw new \Exception( "不支持该类型" );
		}

		// 生成随机名字
		$this->fileName = Random::randStr( $this->randNameLength );

		// 目标全名
		$target_file_name = "{$this->targetFolder}/{$this->fileName}.{$this->ext}";

		// 移动原图到存放目录
		$move_result = file_put_contents( $target_file_name, base64_decode( $content ) );
		if( $move_result == false ){
			throw new \Exception( "移动文件失败" );
		}
		// 源文件信息
		$this->originFileInfo = $this->getImageInfoFormatData( $target_file_name );
		return $this;
	}
1321867
public function setJsonContent($content)
    {
        $context = $this->_context;

        $this->setHeader('Content-Type', 'application/json; charset=utf-8');

        if (is_array($content)) {
            if (!isset($content['code'])) {
                $content = ['code' => 0, 'message' => '', 'data' => $content];
            }
        } elseif ($content instanceof \JsonSerializable) {
            $content = ['code' => 0, 'message' => '', 'data' => $content];
        } elseif (is_string($content)) {
            null;
        } elseif (is_int($content)) {
            $content = ['code' => $content, 'message' => ''];
        } elseif ($content === null) {
            $content = ['code' => 0, 'message' => '', 'data' => null];
        } elseif ($content instanceof ValidatorException) {
            $content = ['code' => -2, 'message' => $content->getMessage()];
        } elseif ($content instanceof \Exception) {
            if ($content instanceof \ManaPHP\Exception) {
                $this->setStatus($content->getStatusCode());
                $content = $content->getJson();
            } else {
                $this->setStatus(500);
                $content = ['code' => 500, 'message' => 'Server Internal Error'];
            }
        }

        $context->content = $this->_jsonEncode($content);

        return $this;
    }
969870
public function base64($content = '') {
        $this->renderer->setHeight($this->width);
        $this->renderer->setWidth($this->height);
        $writer = new Writer($this->renderer);
        //header('Content-type:image/png');
        $png         = $writer->writeString($content);
        $imageString = base64_encode($png);
        return $imageString;
    }
250009
def write_json_base64(str)
      @context.write(trans)
      trans.write(@@kJSONStringDelimiter)
      trans.write(Base64.strict_encode64(str))
      trans.write(@@kJSONStringDelimiter)
    end
352312
public function encrypt($value, string $key, bool $base64 = false): string
    {
        $ret = $this->encryptBinary(serialize($value), $key);
        return ($base64) ? base64_encode($ret) : $ret;
    }
678282
protected function send($content)
	{
		$streamOptions = array(
			'http' => array(
				'method'  => 'POST',
				'header'  => 'Content-Type: application/json',
				'content' => $content,
			)
		);

		$context = stream_context_create($streamOptions);
		$result = @file_get_contents($this->getServerUrl(), false, $context);

		if ($result === false) {
			throw new Exception('Unable to connect to server');
		}

		return $result;
	}
1107322
func (ns *Namespace) Base64Encode(content interface{}) (string, error) {
	conv, err := cast.ToStringE(content)
	if err != nil {
		return "", err
	}

	return base64.StdEncoding.EncodeToString([]byte(conv)), nil
}
1116810
private function processContent($content)
    {
        $this->mimetype = null;
        foreach ($content as $asset) {
            if (null === $this->mimetype) {
                $this->mimetype = $asset->mimetype;
            }

            if ($asset->mimetype !== $this->mimetype) {
                throw new Exception\RuntimeException(
                    sprintf(
                        'Asset "%s" doesn\'t have the expected mime-type "%s".',
                        $asset->getTargetPath(),
                        $this->mimetype
                    )
                );
            }

            $this->setLastModified(
                max(
                    $asset->getLastModified(),
                    $this->getLastModified()
                )
            );
            $this->setContent(
                $this->getContent() . $asset->dump()
            );
        }
    }
489242
public static function create($base64)
    {
        if (($pos = strpos($base64, self::STOPPER)) !== false) {
            $base64 = substr($base64, $pos + strlen(self::STOPPER));
        }

        return \Yii::createObject([
            'class'  => self::className(),
            'base64' => $base64
        ]);
    }
1036144
public static String encrypt(Key key, String content) throws Exception {
        try {
            Cipher cipher = Cipher.getInstance(CRYPTO_ALGORITHM);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return Base64.encodeBase64String(cipher.doFinal(content.getBytes()));
        } catch (Exception e) {
            log.error("Error while encrypting", e);
            throw e;
        }
    }
1227685
func (p Protected) Base64() ([]byte, error) {
	b, err := json.Marshal(map[string]interface{}(p))
	if err != nil {
		return nil, err
	}
	return Base64Encode(b), nil
}
37710
public static byte[] decodeBase64(String base64) {
    if (base64 == null)
      throw new NullPointerException("Parameter 'base64' cannot be null.");

    String fixedBase64 = padBase64(base64);
    return Base64.getDecoder().decode(fixedBase64);
  }
746041
public static String encode(String content) {
		if (content == null || content.length() == 0) {
			return content;
		}
		return org.apache.commons.codec.binary.Base64.encodeBase64String(content.getBytes()).trim();

	}
431023
public function to_base64()
    {
        if (!empty($this->get_upload_path())) {
            return \base64_encode(\file_get_contents($this->get_upload_path()));
        }

        return \base64_encode(\file_get_contents($this->get_tmp_path()));
    }
812505
public static String decodeBase64(String content, TestContext context) {
        return new DecodeBase64Function().execute(Collections.singletonList(content), context);
    }
1237703
@Override
    public String encodeBase64(byte[] value) {
        return new String(Base64.encodeBase64(value), Charsets.UTF_8);
    }
936020
public Packer loadStringBase64(final String in) throws InvalidInputDataException {
		return loadBytes(Base64.decode(in.getBytes(charsetISOLatin1)));
	}