Skip to Content
Java Cryptography
book

Java Cryptography

by Jonathan Knudsen
May 1998
Intermediate to advanced
362 pages
10h 8m
English
O'Reilly Media, Inc.
Content preview from Java Cryptography

Name

Class javax.crypto.Cipher

Description

This class represents a cryptographic cipher, either symmetric or asymmetric. To get a cipher for a particular algorithm, call one of the getInstance() methods. You should specify an algorithm name, a cipher mode, and a padding scheme. The cipher should be initialized for encryption or decryption using the init() method and an appropriate key. To actually perform the encryption or decryption, use update() and doFinal(). The following example shows how to encrypt plaintext using a DES cipher in ECB mode with PKCS#5 padding:

public byte[] simpleEncrypt(byte[] plaintext, Key key) throws Exception 
{
  Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
  cipher.init(Cipher.ENCRYPT_MODE, key);
  byte[] ciphertext = cipher.doFinal(stringBytes);
  return ciphertext;
}

Class Definition

public class javax.crypto.Cipher
  extends java.lang.Object {

  // Constants
  public static final int DECRYPT_MODE;
  public static final int ENCRYPT_MODE;

  // Constructors
  protected Cipher(CipherSpi, Provider, String);

  // Class Methods
  public static final Cipher getInstance(String);
  public static final Cipher getInstance(String, String);

  // Instance Methods
  public final byte[] doFinal();
  public final byte[] doFinal(byte[]);
  public final int doFinal(byte[], int);
  public final byte[] doFinal(byte[], int, int);
public final int doFinal(byte[], int, int, byte[]); public final int doFinal(byte[], int, int, byte[], int); public final int getBlockSize(); public final byte[] getIV(); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Cryptography and Cryptanalysis in Java: Creating and Programming Advanced Algorithms with Java SE 17 LTS and Jakarta EE 10

Cryptography and Cryptanalysis in Java: Creating and Programming Advanced Algorithms with Java SE 17 LTS and Jakarta EE 10

Stefania Loredana Nita, Marius Iulian Mihailescu
Java Security Handbook

Java Security Handbook

Jamie Jaworski, Paul J. Perrone, Venkata S.R. Krishna Chaganti

Publisher Resources

ISBN: 1565924029Errata Page