Welcome Guest, you are in: Login

MUST Creative Engineering Laboratory

RSS RSS

Navigation



Technical Doc



Search the wiki
»

MUST Corp.

MUST Corp.

www.must.or.kr

 Microsoft CERTIFIED Partner Software Development, Web Development, Data Platform

 Microsoft Small Business Specialist

MCSD

Microsoft Certified IT Professional

Microsoft Certified Professional Developer

Page History: [PHP] 서명(signature) 생성 샘플코드

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: 2012/06/04 09:59


서명(signature) 생성 PHP 샘플코드



here is slight difference between .Net and PHP. While .Net expects byte array as key, PHP expects string as key. Thus we have to form string representing byte array.

예제1

  • 텍스트(t)를 자동 생성코자 할때

<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$sig = hash_hmac('sha256', "t=HelloWorld&r=10", $key);
echo '<img src="http://mqr.kr/qr/?t=HelloWorld&amp;r=10&amp;sign='.$sig.'"/>';
?>

예제2

  • 현재 날짜 / 시간으로 QR 코드를 생성을위한 PHP 코드 샘플

<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$text = date('Y.m.d H:i:s');
$query = 't='.urlencode($text).'&r=10&j=1&m=20&lb=fccd13&lt=ed1e2e&rt=155ca2';
$sig = hash_hmac('sha256', $query, $key);
echo '<img src="http://mqr.kr/qr/?'.htmlentities($query).'&amp;sign='.$sig.'"/>';
?>

  • $text 변수에 텍스트를 삽입할 수 있습니다

예제3

  • 현재 홈페이지 URL 자동 생성을위한 PHP 코드 샘플

<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$text = $_SERVER["REQUEST_URI"];
$query = 't='.urlencode($text).'&r=10&j=1&m=20&lb=fccd13&lt=ed1e2e&rt=155ca2';
$sig = hash_hmac('sha256', $query, $key);
echo '<img src="http://mqr.kr/qr/?'.htmlentities($query).'&amp;sign='.$sig.'"/>';
?>

  • $text 변수에 URL을 삽입할 수 있습니다. 아파치서버에서 작동합니다.

MUST Creative Engineering Laboratory

ImageImage Image Image

Image Image Image Image Image Image Image

Copyright © 2010 MUST Corp. All rights reserved. must@must.or.kr
This Program is released under the GNU General Public License v2. View the GNU General Public License v2 or visit the GNU website.