加密/解密数据php(Encrypted/Decrypted data php)
我正在尝试加密/解密来自表单的数据。我参加了帮助我这样做的课程:
https://github.com/o/crypt-php
加密工作,但当我尝试解密时,它给我一个错误说:
带有消息的未捕获异常“异常”'给定数据似乎没有使用Crypt加密'
我的代码:
//for encrypt(this works) require_once("Crypt.php"); $crypt = new Crypt; $crypt->setKey('keykeykeyy'); $password = $_POST['password']; $crypt->setData($password); $encrypted = $crypt->encrypt(); //for decrypt almost the same thing $password = $_POST['password']; $crypt->setData($password); $decrypted = $crypt->decrypt();
有什么问题?
I'm trying to encrypt/decrypt data from a form.I took the class that helps me to do that from:
https://github.com/o/crypt-php
The encrypt works but when I try to decrypt it gives me an error saying that:
Uncaught exception 'Exception' with message 'The given data does not appear to be encrypted with Crypt'
My code:
//for encrypt(this works) require_once("Crypt.php"); $crypt = new Crypt; $crypt->setKey('keykeykeyy'); $password = $_POST['password']; $crypt->setData($password); $encrypted = $crypt->encrypt(); //for decrypt almost the same thing $password = $_POST['password']; $crypt->setData($password); $decrypted = $crypt->decrypt();
What's the problem?
原文:https://stackoverflow.com/questions/41367026
最满意答案
弗兰克的评论是您想要简单地启用/禁用一组小部件的内容,但我将回答您关于如何将状态更改应用于一组对象的更一般的问题。 如果您可以自由使用C ++ 11,那么以下内容将为您提供使用一组通用函数参数在任何对象上调用任何成员函数的一般功能:
// Member functions without arguments template<typename ObjectPtrs, typename Func> void batchApply(ObjectPtrs objects, Func func) { for (auto object : objects) { (object->*func)(); } } // Member functions with 1 or more arguments template<typename ObjectPtrs, typename Func, typename ... Args> void batchApply(ObjectPtrs objects, Func func, Args ... args) { for (auto object : objects) { (object->*func)(args ...); } }
通过上述内容,您可以实现以下目标:只需一行代码即可在一组对象上调用函数。 你会使用这样的东西:
QCheckbox b1, b2, b3, b4, b5; auto Box_1to5 = {b1, b2, b3, b4, b5}; batchApply(Box_1to5, &QCheckbox::setChecked, false); batchApply(Box_1to5, &QCheckbox::toggle);
上述方法的一个限制是它不处理默认函数参数,因此即使函数具有默认参数,也必须显式提供一个。 例如,以下将导致编译器错误,因为
animateClick
有一个参数(忽略其默认值):batchApply(Box_1to5, &QCheckbox::animateClick);
上述技术使用可变参数模板来支持任何数量和类型的函数参数。 如果您还不熟悉这些,可能会发现以下内容:
https://crascit.com/2015/03/21/practical-uses-for-variadic-templates/
Frank's comment is what you want for simply enabling/disabling a set of widgets, but I'll answer your more general question of how to apply a change of state to a set of objects. If you are free to use C++11, then the following will give you the general ability to call any member function on any object with a common set of function arguments:
// Member functions without arguments template<typename ObjectPtrs, typename Func> void batchApply(ObjectPtrs objects, Func func) { for (auto object : objects) { (object->*func)(); } } // Member functions with 1 or more arguments template<typename ObjectPtrs, typename Func, typename ... Args> void batchApply(ObjectPtrs objects, Func func, Args ... args) { for (auto object : objects) { (object->*func)(args ...); } }
With the above, you can achieve your goal of being able to call a function on a set of objects with a single line of code. You would use it something like this:
QCheckbox b1, b2, b3, b4, b5; auto Box_1to5 = {b1, b2, b3, b4, b5}; batchApply(Box_1to5, &QCheckbox::setChecked, false); batchApply(Box_1to5, &QCheckbox::toggle);
The one limitation of the above method is that it doesn't handle default function arguments, so even if a function has a default argument, you have to explicitly provide one. For example, the following will result in a compiler error because
animateClick
has one argument (its default value is ignored):batchApply(Box_1to5, &QCheckbox::animateClick);
The above technique uses variadic templates to support any number and type of function arguments. If you are not yet familiar with these, you may find the following useful:
https://crascit.com/2015/03/21/practical-uses-for-variadic-templates/
相关问答
更多-
同类的组对象C#(Group objects of same kind C#)[2023-11-30]
那么,这样的事情可以与LINQ一起工作: var groups = collections.GroupBy(x => new { x.E1, x.E2, x.E3 }); 这会给你一个你可以迭代的分组序列。 例如: var groups = collections.GroupBy(x => new { x.E1, x.E2, x.E3 }); foreach (var group in groups) { Console.WriteLine("Key: {0}", group.Key); ... -
您可以使用Array.reduce()和helper数组来对这些项目进行分组。 helper数组保存每个组中的make。 对于每个对象,您可以使用Array.findIndex()查找不包含make 。 如果不存在,则新组,并更新helper 。 const cars = [{"make":"audi","model":"r8","year":"2012"},{"make":"audi","model":"rs5","year":"2013"},{"make":"ford","model":"mustang ...
-
只需将'var group'保留为全局变量,就可以将其用于任何操作。 它不需要ID或名称。 Just keep the 'var group' as a global variable and you can use it as it is for any manipulation. It does not need an Id or name.
-
你的代码的问题是它做了两次工作并且查询了两次db。 你可以做的是用select_related (只查询一次published数据)和order_by查询一次: articles = Article.objects.select_related('published').order_by('published') 然后使用此查询集完成所有工作: def getLatest(queryset): latest = queryset.first() if latest == None: ...
-
组对象(Group of objects)[2023-06-26]
弗兰克的评论是您想要简单地启用/禁用一组小部件的内容,但我将回答您关于如何将状态更改应用于一组对象的更一般的问题。 如果您可以自由使用C ++ 11,那么以下内容将为您提供使用一组通用函数参数在任何对象上调用任何成员函数的一般功能: // Member functions without arguments templatevoid batchApply(ObjectPtrs objects, Func func) { fo ... -
您必须存储每个矩形的x,y位置。 您可以为此创建一个新类。 我给你举了一个例子: var Alien = function(x, y) { this.x = x; this.y = y; this.posx = 30 + x*30; this.posy = 90 + y*30; this.go_right = true; this.go_down = false; this.perrow = 3; } Alien.prototype.move = f ...
-
组动态创建的对象(Group Dynamically created objects)[2022-02-14]
尝试将StackPanel放在新的GroupBox中 private void btnAddTitle_Click(object sender, RoutedEventArgs e) { CurrentSortItem++; SortItems.Add(CurrentSortItem); GroupBox gb = new GroupBox(); StackPanel sp = new StackPanel() { Orientation = Orientation.Ho ... -
具有相同字段值的组对象(group objects with same field value)[2021-12-04]
我最终使用的代码是这样的: from itertools import groupby day_set = store.schedule_set.all()[0].day_set.all() schedule = dict() for k, v in groupby(day_set, lambda x: x.day): schedule[k] = list(v) 并将时间表发送到模板进行渲染,这就像魅力一样。 The code I ended up using is th ... -
如何使用SQL查询枚举属于文件组的所有对象?(How to enumerate all the objects belonging to a file group using SQL query?)[2022-05-31]
来自http://blog.sqlauthority.com/2009/06/01/sql-server-list-all-objects-created-on-all-filegroups-in-database/ SELECT o.[name], o.[type], i.[name], i.[index_id], f.[name] FROM sys.indexes i INNER JOIN sys.filegroups f ON i.data_space_id = f.data_space_id INN ... -
像这样的东西? var data = [ { values: [2, 7, 1] }, { values: [1, 2, 7] }, { values: [7, 1, 2] }, { values: [3, 4, 5] }, { values: [2, 1, 8] }, { values: [2, 1, 8] }, ]; var hash = {}; for(var obj of data) { var key = obj.values.sort().jo ...