add secret decoder ring for JSS 3.1.2, special release for CMS.

git-svn-id: svn://10.0.0.236/trunk@112405 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
nicolson%netscape.com 2002-01-17 22:54:05 +00:00
parent 1d65d69394
commit b87005ddaf

View File

@ -36,6 +36,8 @@
package org.mozilla.jss.crypto;
import java.io.UnsupportedEncodingException;
/**
* This is a proprietary NSS interface. It is used for encrypting
* data with a secret key stored in the NSS key database (which is in turn
@ -58,6 +60,8 @@ package org.mozilla.jss.crypto;
*/
public class SecretDecoderRing {
public static final String encodingFormat = "UTF-8";
/**
* Encrypts the given plaintext with the Secret Decoder Ring key stored
* in the NSS key database.
@ -65,10 +69,39 @@ public class SecretDecoderRing {
public native byte[] encrypt(byte[] plaintext)
throws TokenException;
/**
* Encrypts the given plaintext string with the Secret Decoder Ring key
* stored in the NSS key database.
*/
public byte[] encrypt(String plaintext) throws TokenException {
try {
return encrypt(plaintext.getBytes(encodingFormat));
} catch(UnsupportedEncodingException e) {
// this shouldn't happen, because we use a universally-supported
// charset
throw new RuntimeException(e.getMessage());
}
}
/**
* Decrypts the given ciphertext with the Secret Decoder Ring key stored
* in the NSS key database.
*/
public native byte[] decrypt(byte[] ciphertext)
throws TokenException;
/**
* Decrypts the given ciphertext with the Secret Decoder Ring key stored
* in the NSS key database, returning the original plaintext string.
*/
public String decryptToString(byte[] ciphertext)
throws TokenException {
try {
return new String(decrypt(ciphertext), encodingFormat);
} catch(UnsupportedEncodingException e) {
// this shouldn't happen, because we use a universally-supported
// charset
throw new RuntimeException(e.getMessage());
}
}
}