**

Macbook Air 安装crypto++并用Xcode实现的方法

**

适用于初学密码学的同学们。

密码学相关问题:如请用RSA算法加密什么,要求是用crypto++或者Java Crytography Architecture(JCA)实现。
前者就是用C++实现的库,后者是Java实现的库。很多同学像我一样,对C++可能较为熟悉,所以毅然的选择了前者。

问题是不了解crypto++这个东西是什么,怎么用等等。

先解决一下是什么,怎么安装吧!

下面是链接,注意都是在终端下进行的。
https://www.cryptopp.com/wiki/GNUmakefile#config.recommend

  1. 这三行是从git里直接下载包,链接里能找的到这三行,下面还需配置和测试啥的,泡杯茶慢慢来。

    git clone git://github.com/weidai11/cryptopp.git 	cd
            cryptopp 	
            make
    
  2. 导入。

    $ export CXXFLAGS="-DNDEBUG -g2 -O2 -stdlib=libc++" $ make g++$ export CXXFLAGS="-DNDEBUG -g2 -O2 -stdlib=libc++" $ make g++
            -DNDEBUG -g2 -O2 -stdlib=libc++ -fPIC -march=native -pipe -c cryptlib.cpp g++ -DNDEBUG -g2 -O2 -stdlib=libc++ -fPIC -march=native
            -pipe -c cpu.cpp
    
  3. Testing the Library

    # Validation Suite
    $ ./cryptest.exe v
    ...
    	All tests passed!
    Test ended at Sun Jan  3 08:50:06 2016
    And:
    
    # Test Vectors
    $ ./cryptest.exe tv all
    ...
    Tests complete. Total tests = 4111. Failed tests = 0.
    
    
  4. 构建和安装共三步
    ·first

    # Clean previous stuff
    $ make clean
    

    ·second

    # Install directory, not the data directory
    $ make install PREFIX=/tmp/local/
    mkdir -p /tmp/local/include/cryptopp
    cp *.h /tmp/local/include/cryptopp
    chmod 755 /tmp/local/include/cryptopp
    chmod 644 /tmp/local/include/cryptopp/*.h
    mkdir -p /tmp/local/lib
    cp libcryptopp.a /tmp/local/lib
    chmod 644 /tmp/local/lib/libcryptopp.a
    mkdir -p /tmp/local/bin
    cp cryptest.exe /tmp/local/bin
    chmod 755 /tmp/local/bin/cryptest.exe
    mkdir -p /tmp/local/share/cryptopp
    cp -r TestData /tmp/local/share/cryptopp
    cp -r TestVectors /tmp/local/share/cryptopp
    chmod 755 /tmp/local/share/cryptopp
    chmod 755 /tmp/local/share/cryptopp/TestData
    chmod 755 /tmp/local/share/cryptopp/TestVectors
    chmod 644 /tmp/local/share/cryptopp/TestData/*.dat
    chmod 644 /tmp/local/share/cryptopp/TestVectors/*.txt
    

    ·third

    $ cd /tmp/local/bin/
    $ ./cryptest.exe v
    Using seed: 1451851092      
    
    Testing Settings...
    ...
    All tests passed!
    Test ended at Sun Jan  3 08:50:06 2016
    

再解决一下怎么用。

https://github.com/zfwang96/RSA-Cryptopp/
这个链接用的是RSA加密算法.
Macbook Air 安装crypto++并用Xcode实现的方法
下载一下中间两个文件到cryptopp相同的目录下。

接下来你就按照下面的终端口令运行即可。不懂的命令可以度娘啊。

Good: the following will compile and link against your copy of the library. Your copy of the library is located in ./cryptopp.

$ ls
cryptopp        test.cxx

$ g++ -DNDEBUG -g2 -O2 -I . RSA_Gen.cpp -o RSA_Gen ./cryptopp/libcryptopp.a
$ g++ -DNDEBUG -g2 -O2 -I . RSA.cpp -o RSA ./cryptopp/libcryptopp.a
$ ./RSA_Gen
86 bits saved in plain.txt
43 byte(s) Random String Generated Successfully in plain.txt
1024 bits saved in key.txt
1024 bits saved in d.txt
8 bits saved in e.txt

./RSA -e
Plaintext is the following: 
1?c???zw_????d=?d?b
Encryption Success. Ciphertext is the following: 
?՟??j?{???K??n?S;S?+C?r???ň????"?|??D$?;??
                         ?gݲ???<?????Aq?[??1???y??7?m????Yf?

./RSA -d
Ciphertext is the following: 
?՟??j?{???K??n?S;S?+C?r???ň????"?|??D$?;??
                         ?gݲ???<?????Aq?[??1???y??7?m????Yf?
Descryption Success. Plaintext is the following: 
1?c???zw_????d=?d?b

Encryption Success.我们知道加密成功了。
Descryption Success.我们知道解密成功了。

over~

相关文章:

  • 2021-05-18
  • 2021-11-20
  • 2021-04-13
  • 2022-01-17
  • 2022-12-23
  • 2021-11-20
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2022-02-10
  • 2022-12-23
  • 2021-12-06
  • 2021-05-19
  • 2022-12-23
  • 2022-02-09
  • 2021-06-04
相关资源
相似解决方案