12.3 Big Integers and Cryptography The BigInteger class also contains methods that are useful for cryptography. Although this topic is beyond the scope of this book, it's worth a quick look. A public key encryption system requires two keys. All message senders know the public key, which they use to encrypt their messages. Only the recipient of the messages knows the private key, which he or she uses to decrypt the messages. The trick is to be able to give out the public key to multiple senders of secret messages, without making it easy to then figure out the corresponding private key that decrypts the messages. One scheme for generating keys relies on the fact that it is extremely difficult to factor a very large number (50 digits or more) that is the product of two primes. [2]
Class BigInteger has a constructor that generates a large, random integer value with a certain level of certainty that it is prime. Arguments to this constructor include the desired bit length of the number and the certainty level. The higher the certainty level, the longer it takes this constructor to create a BigInteger object. Method isProbablePrime() tests a given BigInteger value to determine, to a given level of certainty, whether or not the value is prime. Like the constructor, the higher the level of certainty, the longer it takes this method to execute. (We'll examine primality testing in Chapter 15.) Encrypting and decrypting messages involves modulo arithmetic [3] with large integer values, and BigInteger includes the methods modInverse() and modPow() .
|
Top |