QR编码解码使用Zxing包

上传人:飞*** 文档编号:43665285 上传时间:2018-06-07 格式:DOC 页数:3 大小:35.50KB
返回 下载 相关 举报
QR编码解码使用Zxing包_第1页
第1页 / 共3页
QR编码解码使用Zxing包_第2页
第2页 / 共3页
QR编码解码使用Zxing包_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《QR编码解码使用Zxing包》由会员分享,可在线阅读,更多相关《QR编码解码使用Zxing包(3页珍藏版)》请在金锄头文库上搜索。

1、QR 编码解码使用 Zxing 包package hustspy.toolbox.barcode;import hustspy.toolbox.cipher.BaseTrans; import hustspy.toolbox.cipher.RSAToolBox;import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.security.PrivateKey; import java.security.PublicKey; import java.util.H

2、ashtable; import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; import com.google.zxing.MultiFormatWriter; import com.googl

3、e.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.client.j2se.MatrixToImageWriter; import mon.BitMatrix; import mon.HybridBinarizer; public class QRCode public static void

4、 main(String args) String text = “华中科技大学-IDC“;String path = “D:hust.png“;QRCode.encode(text, path);String str = QRCode.decode(path);System.out.println(str);/ QR 编码与 RSA 加密相结合 / PublicKey pubKey = RSAToolBox.PublicKeyLoadFromPem(“public.pem“); /PrivateKey priKey = RSAToolBox.PrivateKeyLoadFromPem(“pr

5、ivate.pem“);/ 加密信息 /byte enBytes = RSAToolBox.PrivateKeyEncrypt(text.getBytes(), priKey);/ QR 编码 /QRCode.encode(BaseTrans.encodeToString(enBytes, false), path);/ QR 解码 /String deStr = QRCode.decode(path);/ 解密信息 /byte deBytes = RSAToolBox.PublicKeyDecrypt(BaseTrans.decode(deStr.getBytes(), pubKey); /

6、 /System.out.println(new String(deBytes).trim(); / 编码public static void encode(String str, String path) try BitMatrix byteMatrix; byteMatrix = new MultiFormatWriter().encode(new String(str.getBytes(“GBK“),“iso-8859-1“), BarcodeFormat.QR_CODE, 200, 200); File file = new File(path); MatrixToImageWrite

7、r.writeToFile(byteMatrix, “png“, file); catch (Exception e) e.printStackTrace(); / 解码 public static String decode(String path) String deStr = null;try Reader reader = new MultiFormatReader();File file = new File(path); BufferedImage image; try image = ImageIO.read(file); if (image = null) System.out

8、.println(“Could not decode image“); LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer( source); Result result; Hashtable hints = new Hashtable(); hints.put(DecodeHintType.CHARACTER_SET, “GBK“); result = new MultiFormatReader(

9、).decode(bitmap, hints); String resultStr = result.getText(); System.out.println(result.getBarcodeFormat() + “n“ + resultStr); deStr = resultStr; catch (IOException ioe) System.out.println(ioe.toString(); catch (ReaderException re) System.out.println(re.toString(); catch (Exception e) e.printStackTrace(); return deStr;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号