免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 812 | 回复: 0
打印 上一主题 下一主题

示例备件:易用的加密文件系统 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-03 12:01 |只看该作者 |倒序浏览

                                                                                                在liunx 下使用加密文件系统,相对简单的多。。
本例使用内核自备的 Cryptoloop 来建立 aes 加密的文件系统映像文件。
首先要在内核中启用Cryptoloop:
Device Drivers/Block devices 里的 Loopback device support 为 Y,Cryptoloop Support 为 M 或 Y(本例脚本对应的是M)
其次,要在 Cryptographic API 里将  AES cipher algorithms(AES cipher algorithms (i586))为 M 或 Y
然后参考下面的脚本(保存为任意名.sh,然后chmod +x 给予运行权限,运行它):
               
               
               
               
#!/bin/bash
# by ArLi, program@163.com 200804
if [ "$LOGNAME" != "root" ]
then
    echo "You need to be root to run this script" >&2
    exit 1;
fi
if [ "$#" -lt 1 ]
then
    echo "syntax:";
    echo "\"$0 c imagefilename bytes[K/M/G]\" to create image";
    echo "\"$0 m imagefilename\" to mount";
    echo "\"$0 u\" to umount";
elif [ "$1" = "c" ]
then
    if [ "$#" -lt 3 ]
    then
        echo "args error!" >&2
        exit 1;
    fi;
   
    echo "delete $2 if exist..";
    rm -f $2;
    echo "create image..";
    touch $2;
    echo "shred new image..";
    shred -n1 -s$3 $2;
    if (($(lsmod |grep -c "cryptoloop")  1))
    then
        echo "cryptoloop load..";
        modprobe cryptoloop;
    fi;
    declare loopX=`losetup -f`
    echo "setup encrypting @ $loopX, input password pls..";
    losetup -e aes $loopX $2;
    echo "format image..";
    mkfs.ext3 $loopX
    echo "$2 created";
    losetup -d $loopX
elif [ "$1" = "m" ]
then
    if [ "$#" -lt 2 ]
    then
        echo "imagefilename need!" >&2
        exit 1;
    fi;
    if (($(lsmod |grep -c "cryptoloop")  1))
    then
        echo "cryptoloop load..";
        modprobe cryptoloop;
    fi;
    mount -t ext3 $2 /mnt/encrypt -oencryption=aes;
elif [ "$1" = "u" ]
then
    umount /mnt/encrypt;
    if (($(lsmod |grep -c "cryptoloop") > 0))
    then
        echo "cryptoloop unload..";
        modprobe -r cryptoloop;
    fi;
else
    echo "wrong command." >&2
fi
               
               
               
               
               
               
               
               
                对于aes 未自动载入的可自行在脚本里加上 modprobe aes_generic(aes-i586),可用 cat /proc/crypto 确定 aes 是否已开始工作。
脚本中的 modprobe 也可换成 insmod 和 rmmod。
脚本中的挂载点是 /mnt/encrypt 可自行更改。
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/27936/showart_516110.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP