- 安装PBC库,我是为了实现可搜索加密
C版本代码:https://github.com/atulmahind/PEKShttps://github.com/carebon/PEKShttps://github.com/atulmahind/PEKS
Python版本代码:https://github.com/carebon/Public-Key-Encryption-with-Keyword-Search还没试过
C版本代码前两步还很顺利,运行环境是Ubuntu18.04
1.首先安装GMP库
$ sudo apt-get install libgmp3-dev
2.然后安装OpenSSL
$ sudo apt-get install libssl-dev
3.然后安装PBC库,Github上推荐的是
$ ./configure --prefix=$HOME/.local
$ make
$ make install
但是PBC需要到PBC Library - Pairing-Based Cryptography - Downloads 下载,我选的第一个
下载完成后
sudo su
./configure
make
make install
至此安装完成PBC,但是我在使用过程中,第二步make出不来,参考(PBC库安装_TBBetter的博客-优快云博客PBC库错误总结及解决办法(更新中)_小莱昂纳德的博客-优快云博客)是缺少依赖库
4
sudo apt install m4 (注意小写m,装不上,先sudo apt update一下)
sudo apt install flex
sudo apt install bison
于是正确完整顺序应该是
sudo apt-get install libgmp3-dev
sudo apt-get install libssl-dev
sudo apt install m4 (注意小写m,装不上,先sudo apt update一下)
sudo apt install flex
sudo apt install bison
去下载PBC http://crypto.stanford.edu/pbc/download.html
./configure %没权限的话给一下权限
make
make install
假如直接./configure 默认安装目录是/usr/local/lib
安装上了长这样
但是调用pbc.h编译还需要能找到它,所以头文件需要写成
#include <stdio.h>
#include "/usr/local/include/pbc/pbc.h"
另一个办法是编译的时候写成 -I 指定pbc.h的所在地
gcc bls.c -lgmp -lpbc -I/usr/local/include/pbc -o bls
但是这个我没学会
另外在编译一个程序后出现如下错误
peks: error while loading shared libraries: libpbc.so.1: cannot open shared object file: No such file or directory
-
原因 :这是一个常见错误——找不到动态库 libpbc.so.1,根本原因是,编译程序时没有找到所需动态库,所以程序报错;
-
解决办法 :将动态库 libpbc.so.1 的路径 /usr/local/lib 添加到 LD_LIBRARY_PATH 环境变量;
-
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
上面这句好像是一次性的,需要设置永久的需要更改/etc/profile 参考PBC库安装_TBBetter的博客-优快云博客
sudo gedit /etc/profile
把上面那条设置命令放在文件最下端,注销重新登录
最终成功运行了PEKS