本文整理汇总了Java中com.sun.crypto.provider.SunJCE类的典型用法代码示例。如果您正苦于以下问题:Java SunJCE类的具体用法?Java SunJCE怎么用?Java SunJCE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SunJCE类属于com.sun.crypto.provider包,在下文中一共展示了SunJCE类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public static void main(String argv[]) throws Exception {
String mode = "USE_SKIP_DH_PARAMS";
// Add JCE to the list of providers
SunJCE jce = new SunJCE();
Security.addProvider(jce);
DHKeyAgreement2 keyAgree = new DHKeyAgreement2();
if (argv.length > 1) {
keyAgree.usage();
throw new Exception("Wrong number of command options");
} else if (argv.length == 1) {
if (!(argv[0].equals("-gen"))) {
keyAgree.usage();
throw new Exception("Unrecognized flag: " + argv[0]);
}
mode = "GENERATE_DH_PARAMS";
}
keyAgree.run(mode);
System.out.println("Test Passed");
}
示例2: DESPlus
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public DESPlus(String strKey) throws Exception {
Security.addProvider(new SunJCE());
Key key = getKey(strKey.getBytes());
this.encryptCipher = Cipher.getInstance("DES");
this.encryptCipher.init(1, key);
this.decryptCipher = Cipher.getInstance("DES");
this.decryptCipher.init(2, key);
}
示例3: main
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public static void main(String argv[]) throws Exception {
// Add JCE to the list of providers
SunJCE jce = new SunJCE();
Security.addProvider(jce);
DHKeyAgreement3 keyAgree = new DHKeyAgreement3();
keyAgree.run();
System.out.println("Test Passed");
}
示例4: main
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public static void main(String argv[]) throws Exception {
// Add JCE to the list of providers
SunJCE jce = new SunJCE();
Security.addProvider(jce);
DHKeyFactory test = new DHKeyFactory();
test.run();
System.out.println("Test Passed");
}
示例5: main
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public static void main(String argv[]) throws Exception {
// Add JCE to the list of providers
SunJCE jce = new SunJCE();
Security.addProvider(jce);
TestLeadingZeroes keyAgree = new TestLeadingZeroes();
keyAgree.run();
System.out.println("Test Passed");
}
示例6: DESUtil
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
private DESUtil(String key) throws NoSuchPaddingException,NoSuchAlgorithmException,InvalidKeyException{
Security.addProvider(new SunJCE());
Key _key = getKey(key.getBytes());
encryptCipher = Cipher.getInstance("DES");
encryptCipher.init(Cipher.ENCRYPT_MODE, _key);//加密
decryptCipher = Cipher.getInstance("DES");
decryptCipher.init(Cipher.DECRYPT_MODE, _key);//解密
}
示例7: decrypt
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public static String decrypt(String args, String key) {
try {
Des3Util d3u = new Des3Util();
Security.addProvider(new SunJCE());
return d3u.decryptFromBase64(key, args, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例8: encrypt
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public static String encrypt(String body, String key) {
try {
Des3Util d3u = new Des3Util();
Security.addProvider(new SunJCE());
return d3u.encryptToBase64(key, body, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例9: loadDefaultEncryptionModule
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
/** Load the default encryption module.
*
* <p>By default this is the SunJCE module.
*/
public static void loadDefaultEncryptionModule() {
// Be sure that the cryptographical algorithms are loaded
final Provider[] providers = Security.getProviders();
boolean found = false;
for (final Provider provider : providers) {
if (provider instanceof SunJCE) {
found = true;
break;
}
}
if (!found) {
Security.addProvider(new SunJCE());
}
}
示例10: main
import com.sun.crypto.provider.SunJCE; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Provider prov = new com.sun.crypto.provider.SunJCE();
Security.addProvider(prov);
SecureRandom sr = new SecureRandom();
// Create new DES key.
KeyGenerator kg = KeyGenerator.getInstance("DES");
kg.init(sr);
Key key = kg.generateKey();
// Generate an IV.
byte[] iv_bytes = new byte[8];
sr.nextBytes(iv_bytes);
IvParameterSpec iv = new IvParameterSpec(iv_bytes);
// Create the consumer
Cipher decrypter = Cipher.getInstance("DES/CFB8/NoPadding");
decrypter.init(Cipher.DECRYPT_MODE, key, iv);
PipedInputStream consumer = new PipedInputStream();
InputStream in = new CipherInputStream(consumer, decrypter);
// Create the producer
Cipher encrypter = Cipher.getInstance("DES/CFB8/NoPadding");
encrypter.init(Cipher.ENCRYPT_MODE, key, iv);
PipedOutputStream producer = new PipedOutputStream();
OutputStream out = new CipherOutputStream(producer, encrypter);
producer.connect(consumer); // connect pipe
byte[] plaintext = "abcdef".getBytes();
for (int i = 0; i < plaintext.length; i++) {
out.write(plaintext[i]);
out.flush();
int b = in.read();
String original = new String(plaintext, i, 1);
String result = new String(new byte[] { (byte)b });
System.out.println(" " + original + " -> " + result);
}
}