我有一个在我的开发MacBook Pro上运行良好的测试,但无法在持续集成的TeamCity服务器中运行.
错误如下:
java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
Run Code Online (Sandbox Code Playgroud)
开发盒和TeamCity都使用Java 1.6,我使用BouncyCastle库来满足特殊的AES加密需求.
代码如下:
private byte[] aesEncryptedInfo(String info) throws UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidParameterSpecException, InvalidAlgorithmParameterException, NoSuchProviderException {
Security.addProvider(new BouncyCastleProvider());
SecretKey secret = new SecretKeySpec(CUSTOMLONGSECRETKEY.substring(0, 32).getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
cipher.init(Cipher.ENCRYPT_MODE, secret, new IvParameterSpec(VECTOR_SECRET_KEY.getBytes()));
return cipher.doFinal(info.getBytes("UTF-8"));
}
Run Code Online (Sandbox Code Playgroud)
UPDATE
看起来根据所选答案,我必须在我的TeamCity安装上修改一些东西,它可能会影响一些用户安装 - 所以它不是一个好选择我必须切换到另一个加密库来做到这一点没有限制.所以充满弹性的城堡可能会有所帮助.
更新2
我实际上切换到使用BouncyCastle来避免这种限制.请注意,这仅适用于直接使用自己的BC类,而不是BC提供程序.
嗨,大家好我想从下面的给定文本中找出一个简单的regEx:
<b>Name:</b> Photomatix.Pro.v4.0.64bit-FOSI<br />
Run Code Online (Sandbox Code Playgroud)
我基本上只想输出和存储Photomatix.Pro.v4.0.64bit-FOSI即内部的实际值, 但当我定义它时:
private static final String REG_NAME = "<b>Name:</b>(.*)<br />";
Run Code Online (Sandbox Code Playgroud)
它实际上存储和输出整体 <b>Name:</b> Photomatix.Pro.v4.0.64bit-FOSI<br />
关于如何从上面的xml文本中提取值的任何想法?提前喝彩
我想使用标准从node.js进行传出的HTTP调用http.Client.但我无法直接从我的网络到达远程服务器,需要通过代理.
如何告诉node.js使用代理?
这两个功能disp并display没有返回参数,并显示变量的内容到命令行窗口.
我想将函数调用的结果(显示的字符串)转换为变量而不是输出到命令窗口,这样的str = ToString( myStruct );输入变量是一个MATLAB结构!
我知道显示结果取决于命令窗口的可用宽度,它可以是宽或窄.
在所有现代编程语言中,它都是一种obj.ToString()方法.
在C++中.我可以将大多数事物声明为const,例如:
变量:const int i=5;
Scala有val i=5,但是这只会阻止重新分配,而不是更改对象,如下例所示:
C++:
const int i[]={1,2,3,4};
i[2]=5; //errorRun Code Online (Sandbox Code Playgroud)
斯卡拉: val a=Array(1,2,3,4)
a(2)=5 //a is now Array(1, 2, 5, 4)
使用成员函数会更糟:
C++:
class Foo {
int i;
int iPlusFive() const {return i+5;}
int incrementI(){ return ++i; }
}
我可以肯定,调用iPlusFive不会改变对象,我不会在const对象上不小心调用incrementI.
当涉及到集合时,C++继续使用const集合的const-correct条纹:简单地将你的向量声明为const而你无法改变它.将a分配non-const vector<Int>给a const vector<Int>,编译器不会复制任何内容,并且会阻止您更改now const集合中的任何内容.
Scala有scala.collection.mutable.whatever和scala.collection.immutable.whatever,你不能只将可变集合转换为不可变集合,而且你仍然可以用非const成员函数更改收集的对象.
为什么scala,它有一个非常好的类型系统,没有任何可比的C++ const-keyword?
编辑:
Margus建议使用import scala.collection.mutable.我的解决方案是使用
import scala.collection.mutable.HashMap
import scala.collection.immutable.{HashMap => ConstHashMap}Run Code Online (Sandbox Code Playgroud)
这将使可变HashMap可用作HashMap和不可变的als ConstHashMap,但我仍然更喜欢C++方法. 在编写一个简单的函数来从字符串中删除特定字符时,我遇到了这个奇怪的问题:
void str_remove_chars( char *str, char to_remove)
{
if(str && to_remove)
{
char *ptr = str;
char *cur = str;
while(*ptr != '\0')
{
if(*ptr != to_remove)
{
if(ptr != cur)
{
cur[0] = ptr[0];
}
cur++;
}
ptr++;
}
cur[0] = '\0';
}
}
int main()
{
setbuf(stdout, NULL);
{
char test[] = "string test"; // stack allocation?
printf("Test: %s\n", test);
str_remove_chars(test, ' '); // works
printf("After: %s\n",test);
}
{
char *test = "string test"; // non-writable?
printf("Test: %s\n", …Run Code Online (Sandbox Code Playgroud) 使用我的Ruby脚本:
imap = Net::IMAP.new('imap.gmail.com')
imap.login("some_email@host.com", password)
Run Code Online (Sandbox Code Playgroud)
我得到以下异常:
A connection attempt failed because
the connected party did not properly
respond after a period of time, or
established connection failed because
connected hos has failed to respond. -
connect(2)
Run Code Online (Sandbox Code Playgroud)
怎么了?
persistence.xml为了测试,我有两个文件:
src/main/resources/META-INF/persistence.xmlsrc/test/resources/META-INF/persistence.xml如何指示Maven在测试期间忽略第一个文件?现在它不会被忽视,因为OpenEJB说:
ERROR - FAIL ... Finder: @PersistenceContext unitName has multiple matches:
unitName "abc" has 2 possible matches.
Run Code Online (Sandbox Code Playgroud) 我们有一个网址,我们需要检查网页是否有效.我们尝试了以下代码:WebResponse objResponse = null;
WebRequest objRequest = HttpWebRequest.Create(URL);
objRequest.Method = "HEAD";
try
{
objResponse = objRequest.GetResponse();
objResponse.Close();
}
catch (Exception ex)
{
}
Run Code Online (Sandbox Code Playgroud)
如果无法获得响应,上面的代码给出了异常,但即使我们在该页面上有"服务器错误"也能正常工作?任何帮助如何获得服务器错误?