任何人都可以举个例子,在BouncyCastle中使用带有AES的GCM和/或CCM模式吗?
我的代码是这样的:
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
byte[] block = new byte[1048576];
int i;
long st,et;
cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec);
BufferedInputStream bIn=new BufferedInputStream(new ProgressMonitorInputStream(null,"Encrypting ...",new FileInputStream("input")));
CipherInputStream cIn = new CipherInputStream(bIn, cipher);
BufferedOutputStream bOut=new BufferedOutputStream(new FileOutputStream("output.enc"));
int ch;
while ((i = cIn.read(block)) != -1) {
bOut.write(block, 0, i);
}
cIn.close();
bOut.close();
Thread.sleep(5000);
cipher.init(Cipher.DECRYPT_MODE, key, ivSpec);
BufferedInputStream fis=new BufferedInputStream(new ProgressMonitorInputStream(null,"Decrypting ...",new FileInputStream("output.enc")));
//FileInputStream fis=new FileInputStream("output.enc");
//FileOutputStream ro=new FileOutputStream("regen.plain");
BufferedOutputStream ro=new BufferedOutputStream(new …Run Code Online (Sandbox Code Playgroud) 我想向同事展示SimpleDateFormat 通过简单的JUnit测试不是线程安全的.下面的类没有说明我的观点(在多线程环境中重用SimpleDateFormat),我不明白为什么.你能发现什么阻止我使用SDF抛出运行时异常吗?
public class SimpleDateFormatThreadTest
{
@Test
public void test_SimpleDateFormat_MultiThreaded() throws ParseException{
Date aDate = (new SimpleDateFormat("dd/MM/yyyy").parse("31/12/1999"));
DataFormatter callable = new DataFormatter(aDate);
ExecutorService executor = Executors.newFixedThreadPool(1000);
Collection<DataFormatter> callables = Collections.nCopies(1000, callable);
try{
List<Future<String>> futures = executor.invokeAll(callables);
for (Future f : futures){
try{
assertEquals("31/12/1999", (String) f.get());
}
catch (ExecutionException e){
e.printStackTrace();
}
}
}
catch (InterruptedException e){
e.printStackTrace();
}
}
}
class DataFormatter implements Callable<String>{
static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date;
DataFormatter(Date date){
this.date = date;
} …Run Code Online (Sandbox Code Playgroud) 有没有办法在运行时指定EL中使用的托管bean而不是设计时间?例如
actionListener="#{myBean.method}",myBean根据JSF页面调用代码,部分可以具有不同的值(条件是使用的任何对象而不是myBean是从实现"方法"的公共父派生的).
我在另一个线程中再打开一个阶段时遇到问题.如果我在同一个线程中打开此阶段,则不会出现异常.
void hashMapDeclaration(){
actions2methods.put("NEW", new Runnable() {@Override public void run() { newNetCreation(); }});
actions2methods.put("LOAD", new Runnable() {@Override public void run() { loadNetState(); }});
...... //other hashes
}
HBox buttonBuilder(double spacing,double layoutX,String... bNames){
HBox lBar = new HBox(10);
.... //some code
for(final String text : bNames){ //in my case text variable value is "NEW" so it should run method newNetCreation
Button newButton = new Button();
newButton.setText(text);
.... //code
newButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent paramT) {
Thread t;
EventQueue.isDispatchThread();
t …Run Code Online (Sandbox Code Playgroud) 当我们使用eclipse时,它会为我们的java代码提供建议并显示描述,即显示有关该函数的描述的小型弹出窗口.假设我正在创建一个java库,我需要添加关于我的库中应该被eclipse识别并显示为建议的函数的这些描述,我应该如何指定描述,即我需要使用哪种类型或格式的注释来显示这些关于功能的描述.任何人都可以为我提供解决上述问题的链接.
我们编写了一个补丁,用shell脚本替换数据文件中提供的^ M字符;
sed 's/^M//g' source_file > target_file
Run Code Online (Sandbox Code Playgroud)
但是因为我们使用subversionshell脚本的源代码控制而且我已经指定了eol-style:native属性; ^M当我们接受svn updateUNIX盒子并且变成时,这被新线替换
sed 's/
//g' source_file > target_file
Run Code Online (Sandbox Code Playgroud)
作为一个更好的做法我建议更换该sed有dos2unix
dos2unix source_file > target_file
Run Code Online (Sandbox Code Playgroud)
这摆脱了^M角色,但作为副作用,它还取代了一些不应转换的source_file中可用的有意义的数据.
所以我们想要一种通过shell脚本从数据文件中删除^ M字符的方法,该脚本不应该提及^ M字符,以便它可以通过subversion移植到Windows和Linux机器上?
摆脱这些问题的最佳做法是什么?
java ×5
aes ×1
aes-gcm ×1
annotations ×1
bouncycastle ×1
cryptography ×1
eclipse ×1
el ×1
eol ×1
javadoc ×1
javafx-2 ×1
jsf ×1
shell ×1
svn ×1