• 最安全的加密算法


    在密码学里,有一种理想的加密方案,叫做一次一密乱码本(one-time pad)。

    one-time pad的算法有以下要求:
    1、密钥必须随机产生
    2、密钥不能重复使用
    3、密钥和密文的长度是一样的。

    one-time pad是最安全的加密算法,双方一旦安全交换了密钥,之后交换信息的过程就是绝对安全的啦。这种算法一直在一些要求高度机密的场合使用,据说美国和前苏联之间的热线电话、前苏联的间谍都是使用One-time pad的方式加密的。不管超级计算机工作多久,也不管多少人,用什么方法和技术,具有多大的计算能力,都不可能破解。

    一次一密的一种实现方式,如下:
    public class OneTimePadUtil {
        
    public static byte[] xor(byte[] bytes, byte[] keyBytes) {
            
    if (keyBytes.length != bytes.length) {
                
    throw new IllegalArgumentException();
            }


            
    byte[] resultBytes = new byte[bytes.length];

            
    for (int i = 0; i < resultBytes.length; ++i) {
                resultBytes[i] 
    = (byte) (keyBytes[i] ^ bytes[i]);
            }


            
    return resultBytes;
        }

    }

    使用例子:
    String plainText = "温少";
    String keyText 
    = "密码";

    byte[] plainBytes = plainText.getBytes();
    byte[] keyBytes = keyText.getBytes();

    assert plainBytes.length 
    == keyBytes.length;

    //加密
    byte[] cipherBytes = OneTimePadUtil.xor(plainBytes, keyBytes);

    //解密
    byte[] cipherPlainBytes = OneTimePadUtil.xor(cipherBytes, keyBytes);


    这是最简单的加密算法,但也是最安全的机密算法。前天和朋友讨论到了这个问题,所以写了这篇文章。

  • 相关阅读:
    Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
    ptconfigdiff的使用
    freebsd上安装sudo
    vm9.02的序列号
    pttablechecksum
    "Makefile", line 3: Need an operator
    nc的使用
    vs2005自带的水晶报表破解方法
    [vs2008环境]绑定水晶报表的两种方式(Pull和Push)
    .NET环境下水晶报表使用总结
  • 原文地址:https://www.cnblogs.com/jobs/p/126588.html
Copyright © 2020-2023  润新知