java DES

目录

  • 概述
  • 分组密码的模式
  • DES的Java代码
    • 无模式
    • CTR模式示例

一、概述

Java安全领域主要由JCA、JCE、JSSE、JAAS组成。其中JCA和JCE在jdk1.4中已经合并了,所以在后续的JDK版本中,摘要和常见的加密算法(例如DES)都可以在JDK中直接使用,主要是两个package——java.security和javax.crypto。

引用:Java Cryptography Architecture (JCA) Reference Guide (oracle.com)

  • Prior to JDK 1.4, the JCE was an unbundled product, and as such, the JCA and JCE were regularly referred to as separate, distinct components. As JCE is now bundled in the JDK, the distinction is becoming less apparent. Since the JCE uses the same architecture as the JCA, the JCE should be more properly thought of as a part of the JCA.

  • The JCA within the JDK includes two software components:

    • The framework that defines and supports cryptographic services for which providers supply implementations. This framework includes packages such as java.securityjavax.cryptojavax.crypto.spec, and javax.crypto.interfaces.
    • The actual providers such as SunSunRsaSignSunJCE, which contain the actual cryptographic implementations.

二、分组密码的模式

对称密码体制根据运算单位划分成流密码和分组密码。

流密码每次运算的单位是1bit或1byte,内部需要通过状态来记录加解密的进度;而分组密码每次运算的单位是固定长度的一块数据,数据块的长度需要根据密钥的大小,将明文的分成密钥长度大小的一个个分组,内部不需要状态来记录加解密的进度。

分组密码,例如DES和3DES的分组长度都是64bit,AES的分组长度是128bit。

补充:DES的密钥长度实际上时56bit,因为每隔7bit会设置一个校验位,所以实际密钥长度虽然是56bit,但分组却是64bit

所以,通过分组密码的定义你可以很直观的知道,如果明文比密钥长度要长,那么在进行加密的时候,明文会被分成密钥长度大小的多个分组,最后一个分组如果小于密钥长度,就需要padding。

这时候,通过什么样的次序来迭代处理这些分组,就叫做分组密码的模式。

常见的分组密码的模式有哪些?

几乎任何一本密码学书籍上都有介绍,比较通俗易懂的建议看《图解密码技术》,Java相关的参看javax.crypto.Cipher的api文档或这个连接:Java Security Standard Algorithm Names (oracle.com)

节选如下:

Cipher Algorithm Modes

The following names can be specified as the mode component in a transformation when requesting an instance of Cipher.

Algorithm Name Description
NONE No mode.
CBC Cipher Block Chaining Mode, as defined in FIPS PUB 81.
CCM Counter/CBC Mode, as defined in NIST Special Publication SP 800-38C.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值