我正在尝试用Java加密/解密String.没有关于加密的问题然后存储在sqlite表中.但我总是得到同样的错误试图解密它:
"java.security.InvalidKeyException:当预期时没有设置IV"
这是我的代码片段:
public String encrypt(String password){
try
{
String key = "mysecretpassword";
SecretKeySpec keySpec = null;
keySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
return new String(cipher.doFinal(password.getBytes()));
}
catch (Exception e)
{
return null;
}
}
public String decrypt(String password){
try
{
String key = "mysecretpassword";
SecretKeySpec keySpec = null;
keySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.DECRYPT_MODE,keySpec);
return new String(cipher.doFinal(password.getBytes()));
}
catch (Exception e)
{
System.out.println(e);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有几个自定义报告,我希望能够在触发它们的功能区上添加按钮.
可能吗?如果是这样,任何例子都会很棒!
提前致谢 !
我正在尝试使用我的应用程序打开位于资源文件夹中的pdf。它确实可以在模拟器上运行,但是当我尝试导出的应用程序时却没有任何反应。我猜我没有使用正确的路径,但看不到我错了。getRessource方法可以很好地处理我的图像。
这是一个代码片段:
public void openPdf(String pdf){
if (Desktop.isDesktopSupported()) {
try {
URL monUrl = this.getClass().getResource(pdf);
File myFile = new File(monUrl.toURI());
Desktop.getDesktop().open(myFile);
} catch (IOException ex) {
// no application registered for PDFs
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我这样指的是pdf变量:“ name_of_the_file.pdf”
编辑:我已经粘贴了整个方法
我一直在网上看,但找不到合适的答案......
我在C#中编写了一个插件,当条件满足时,我想设置一个字段readonly ...
提前致谢 !
我按照正确的程序在我的eclipse项目中生成了ITelephony.java类.
但它似乎没有正确生成,因为我在文件中有频繁的红色警告.我在ubuntu 12.04 64位下运行.奇怪的是,它确实适用于在Windows下运行的PC工作.事情是我真的需要在我的笔记本电脑上工作才能在家工作.
我在两台设备上都使用了Juno版本的eclipse.
什么可能导致这个问题?
任何答案/想法都会很棒,因为我真的不知道如何解决它.
编辑1:抱歉忘了指定我得到的错误.所有相同的类型,例如"@Override public android.os.IBinder asBinder(){return this;}"
我得到:"方法asBinder类型()ITelephony.Stub必须重写超类方法"和"实现androidod.IIterface.asBinder".
这是完全生成的文件:
/*
* This file is auto-generated. DO NOT MODIFY.
* Original file: /home/lenore/workspace/Launcher/src/com/android/internal/telephony/ITelephony.aidl
*/
package com.android.internal.telephony;
public interface ITelephony extends android.os.IInterface
{
/** Local-side IPC implementation stub class. */
public static abstract class Stub extends android.os.Binder implements com.android.internal.telephony.ITelephony
{
private static final java.lang.String DESCRIPTOR = "com.android.internal.telephony.ITelephony";
/** Construct the stub at attach it to the interface. */
public Stub()
{
this.attachInterface(this, DESCRIPTOR);
}
/**
* Cast …Run Code Online (Sandbox Code Playgroud)