public ActionResult TaoQR(string data) { if (rsa.PublicOnlyKeyXML == null) { return(Json(new { isError = "Chưa tạo public key" }, JsonRequestBehavior.AllowGet)); } var match = @"[\n]+"; if (data.Contains("\n")) { data = Regex.Replace(data, match, ""); } // Tạo PublicKey, PrivateKey byte[] duLieuBam = QRCode_RSA.Content.ultilities.Common.HashString(data); //var t = Convert.ToBase64String(duLieuBam); var duLieuMaHoa = rsa.Encrypt_string(rsa.PublicOnlyKeyXML, duLieuBam); if (duLieuMaHoa.Contains("Mã hóa thất bại")) { return(Json(new { isError = duLieuMaHoa }, JsonRequestBehavior.AllowGet)); } string TaoQR = data + ",$$$$$ " + duLieuMaHoa; //string TaoQR = Common.FromHexString(duLieuMaHoa); return(Json("" /*Common.TaoQRCode(TaoQR,"")*/, JsonRequestBehavior.AllowGet)); }
public ActionResult TaoQR(int id) { try { if (rsa.PublicOnlyKeyXML == null) { return(Json(new { isError = "Chưa tạo public key" }, JsonRequestBehavior.AllowGet)); } var user = db.Users.FirstOrDefault(n => n.Id == id); string savefilename = DateTime.Now.ToFileTime().ToString(); var duLieu = _iMapperView.Map <User, UserViewModel>(user); var data = user.Id + ",$$$$$ " + Convert.ToBase64String(Encoding.UTF8.GetBytes(user.HoTen)) + ",$$$$$ " + (user.NgaySinh != null ? user.NgaySinh.ToString() : "") + ",$$$$$ " + user.SoHieu.ToString() + ",$$$$$ " + (user.SoBangCap != null ? user.SoBangCap.ToString() : "") + ",$$$$$ " + savefilename; // Tạo PublicKey, PrivateKey byte[] duLieuBam = QRCode_RSA.Content.ultilities.Common.HashString(data); //var t = Convert.ToBase64String(duLieuBam); var duLieuMaHoa = rsa.Encrypt_string(rsa.PublicOnlyKeyXML, duLieuBam); if (duLieuMaHoa.Contains("Mã hóa thất bại")) { return(Json(new { isError = duLieuMaHoa }, JsonRequestBehavior.AllowGet)); } string TaoQR = data + ",$$$$$ " + duLieuMaHoa; //string TaoQR = Common.FromHexString(duLieuMaHoa); // Tạo QR Image var linkQRImage = QRCode_RSA.Content.ultilities.Common.TaoQRCode(TaoQR); var file = ConvertWordtoImage(duLieu, linkQRImage, savefilename); file.txtMaQuet = TaoQR; System.IO.File.Delete(linkQRImage); return(new JsonResult() { Data = file, JsonRequestBehavior = JsonRequestBehavior.AllowGet, MaxJsonLength = int.MaxValue }); //return Json(ConvertWordtoImage(duLieu, linkQRImage), JsonRequestBehavior.AllowGet); } catch (Exception ex) { return(Json(new { isError = "Tạo thất bại: " + ex.Message }, JsonRequestBehavior.AllowGet)); } }