参考:

http://acsc.cs.utexas.edu/cpabe/tutorial.html

http://acsc.cs.utexas.edu/cpabe/

事先先配置好cp-abe:http://www.cnblogs.com/rockorange/p/3757805.html

我在ubuntu的主文件夹下面的hmj文件夹下新建了一个文件cp-abe。路径是:/home/hmj/cp-abe.接下来要执行的命令都要先进入到这个路径下。cd   /home/hmj/cp-abe。 在这个文件夹下产生公钥、私钥。

Using the cpabe Toolkit

First download, untar, compile, and install the most recent tarball of libbswabe, the support library. Next do the cpabe tarball. Each can be installed with the standard GNU build system commands.

1.安装cpabe toolkit

$ ./configure
$ make
$ make install

The "$" denotes your shell’s prompt. Note that the package requires thePBC library, so make sure you have that installed first.

Next, to set up the public key and master keys, run cpabe-setup.

2.通过cpabe-setup命令产生 public key and master key

$ cpabe-setup
$ ls
master_key pub_key

Now you can use the file master_key to produce private keys associated with various sets of attributes. Let’s say you work for a company that just hired two new employees,Sara and Kevin(后面就以这个为例子), and you are going to make private keys for their workstations.

3.使用master_key 和 pub_key 以及cpabe-keygen命令为具有属性值的用户产生私钥

 

To do so, you use cpabe-keygen to generate a key with the listed attributes using public key PUB_KEY and master secret key MASTER_KEY.

Output will be written to the file "sara_priv_key" unless the−o option is specified.

$ cpabe-keygen -o sara_priv_key pub_key master_key \
sysadmin it_department 'office = 1431' 'hire_date = '`date +%s`
$ cpabe-keygen -o kevin_priv_key pub_key master_key \
business_staff strategy_team 'executive_level = 7' \
'office = 2362' 'hire_date = '`date +%s`
$ ls
master_key pub_key sara_priv_key kevin_priv_key

注意:

(1)cp-keygen使用参照:http://acsc.cs.utexas.edu/cpabe/cpabe-keygen.html

(2)第一行代码的末尾有一个“\”是因为第一行放不下了,想换行继续输命令。

(3)上例产生 了两个私钥sara_priv_key kevin_priv_key,分别是sara和kevin的。

 

4.使用cpabe-enc命令和pub_key和访问策略加密明文生成密文 (这里事先新建了一个文件security_report.pdf ,这个文件是要被加密的)

As you can see in those examples, some attributes are assigned a value, while others a key simply "has" without further qualification. Thedate command can be used to help use the current time as an attribute value.

Now suppose later someone wants to encrypt a sensitive document. All they need is the public key, then can usecpabe-enc to encrypt it under a specified policy.

$ ls
pub_key security_report.pdf
$ cpabe-enc pub_key security_report.pdf
(sysadmin and (hire_date < 946702800 or security_team)) or //注意这里一定要换行
(business_staff and 2 of (executive_level >= 5, audit_group, strategy_team))
^D //ctrl+D 表结束输入
$ ls
pub_key security_report.pdf.cpabe
(sysadmin and。。。)这个是访问策略

In this case, they typed the policy on stdin. Note that the attributes of Kevin’s key satisfy this policy, but the attributes of Sara’s key do not.

(在这个例子里,设计的策略是kevin满足,但是sara的不满足)

5.使用cpabe-dec命令,用私钥对密文进行解密。

If Kevin wants to decrypt the document, he can use cpabe-dec.

$ ls
pub_key kevin_priv_key security_report.pdf.cpabe
$ cpabe-dec pub_key kevin_priv_key security_report.pdf.cpabe
$ ls
pub_key kevin_priv_key security_report.pdf

If Sara were to try to decrypt it, an error would be reported.

(如果sara试图解密就会出错,因为sara的属性不符合密文的访问策略,kevin不会)

That’s all there is to using cpabe!

下面是CP-ABE的加解密机制

CP-ABE的使用的更多相关文章

  1. linux之cp/scp命令+scp命令详解

    名称:cp 使用权限:所有使用者 使用方式: cp [options] source dest cp [options] source... directory 说明:将一个档案拷贝至另一档案,或将数 ...

  2. 写给自己:修改配置文件一定要cp一个.bak

    写给自己:修改配置文件一定要cp一个.bak 毕竟不是每次的修改都一定对,而且很多时候是在服务器上直接修改原文件,修改后重启服务才知道是否修改正确,如果不加备份修改,造成服务器动荡,将会造成不可挽回的 ...

  3. mkdir,rmdir,cp,rm,mv,cat,touch用法

    一.mkdir新建目录 1.进入tmp目录,查看该目录下面的子目录 [root@localhost ~]# cd /tmp[root@localhost tmp]# lshsperfdata_root ...

  4. CP

    cp:copy files and directories,如果要拷贝目录,则使用-a或者-r参数,则能够拷贝目录, 如果源文件是多个,那目标文件在最后,且是目录. Cp [-aifpru] [源文件 ...

  5. 关于so文件cp覆盖导致调用者core的研究

    先说cp好mv/rm的区别: cp from to,则被覆盖文件 to的inode依旧不变(属性也不变),内容变为from的: mv from to,则to的inode变为from的,相应的,to的属 ...

  6. Linux命令学习总结:cp命令

    命令简介: cp命令用来复制文件或目录.指令英文原义:copy 指令所在路径:/bin/cp 命令语法: Usage: cp [OPTION]... [-T] SOURCE DEST or: cp [ ...

  7. Linux cp (复制)命令简介

    \cp  -rf  source1  source2   source3   ....   directory cp (复制档案或目录) [root@linux ~]# cp [-adfilprsu] ...

  8. Linux_用户级_常用命令(4):cp

    Linux_用户级_常用命令之cp 开篇语:懒是人类进步的源动力 本文原创,专为光荣之路公众号所有,欢迎转发,但转发请务必写出处! Linux常用命令第二集包含命令:cp 格式 cp  [-optio ...

  9. cp命令

    [root@www ~]# cp [-adfilprsu] 来源文件(source) 目标文件(destination) [root@www ~]# cp [options] source1 sour ...

  10. 【初级】linux cp 命令详解及使用方法实战

    cp:复制文件或者目录 前言: cp命令用来复制文件或者目录,是Linux系统中最常用的命令之一.一般情况下,shell会设置一个别名,在命令行下复制文件时,如果目标文件已经存在,就会询问是否覆盖,不 ...

随机推荐

  1. HDU 1298 T9(字典树+dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1298 题意:模拟手机9键,给出每个单词的使用频率.现在给出按键的顺序,问每次按键后首字是什么(也就是要概率最大的 ...

  2. MyBatis数据库测试代码自动生成

    <!-- generatorConfig.xml配置,其中:<plugin type="org.mybatis.generator.plugins.ToStringPlugin& ...

  3. LCA 模板

    关于LCA: LCA 指树上两点的公共祖先. 如何 “暴力” 找两点的 LCA : 可以先 DFS 一遍求出每个点的 dep (深度).然后从深度大的点先往上跳,跳到与另一个点相同的深度,如果还没有到 ...

  4. 面试题中关于String的常见操作

    题目1: 将用户输入的一段话,每个单词的首字母大写, 每个单词之间的空格调整为只有一个,遇到数字,将数字与后一个单词用下划线 "_" 进行连接 题目2:将 i @@ am @@@ ...

  5. CentOS6.5下搭建LAMP+FreeRadius+Daloradius Web管理和TP-LINK路由器、H3C交换机连接,实现,上网认证和记账功能

    什么是RADIUS服务: RADIUS:(Remote Authentication Dial In User Service)中文名为远程用户拨号认证服务,简称RADIUS,是目前应用最广泛的AAA ...

  6. [转]QT中QString与string的转化,解决中文乱码问题

    QString str2qstr(const string str) { return QString::fromLocal8Bit(str.data()); } string qstr2str(co ...

  7. RxJava + Retrofit

    一.添加依赖 compile 'io.reactivex:rxandroid:1.2.0' compile 'io.reactivex:rxjava:1.1.5' compile 'com.googl ...

  8. python3.5学习第二章(1)标准库,bytes

    一.输出python库的路径: 1.sys标准库 import sysprint(sys.path) 结果: 'E:\\python练习\\python35学习\\Day2', 'E:\\python ...

  9. 00-python语言介绍

    以下为摘录的python的介绍 Python是一种解释型语言.这就是说,与C语言和C的衍生语言不同,Python代码在运行之前不需要编译.其他解释型语言还包括PHP和Ruby. Python是动态类型 ...

  10. 牛客OI周赛6-提高组 A 大法师与魔法石

    大法师与魔法石 思路: 对于一个ai, 它可以构成区间[ai/v, ai] 假设和它相邻的为aj, 那么ai 和 aj 构成的区间为[(ai+aj) / v, ai+aj] 那么这两个区间能合并的条件 ...