大数字,我的意思是,如果你采用一个千兆字节(而不是4/8字节等),并尝试添加/减去/乘以/除以一些其他任意大(或小)的数字.
加法和减法相当容易(一次一个k/m /字节):
out_byteN = a_byteN + b_byteN + overflowBit
Run Code Online (Sandbox Code Playgroud)
对于每个字节,因此我可以在读取磁盘中的数字时进行加/减,而不会冒RAM耗尽的风险.
对于乘法/除法,只需在循环中执行上述操作即可.
但是拿一个巨大数字的第n根呢?
我想使用带有弹性城堡的AES算法在J2ME中加密和解密数据可以任何人给我示例代码
我想使用ECB和PKCS5Padding
提前致谢.
我有以下代码,大约5%的时间抛出CryptographicException,我无法弄清楚为什么a)它不会一直失败b)为什么它完全失败:
// Initialize the new secure keys
var keyGenerator = KeyGenerator.Create();
var keyPair = keyGenerator.GenerateKeyPair();
this._privateKey = keyPair.ToEncryptedPrivateKeyString(privateKeySecret);
this._publicKey = keyPair.ToPublicKeyString();
// Initialize the certificate generation
var certificateGenerator = new X509V3CertificateGenerator();
var serialNo = BigInteger.ProbablePrime(128, new Random());
certificateGenerator.SetSerialNumber(serialNo);
certificateGenerator.SetSubjectDN(GetLicenseeDN());
certificateGenerator.SetIssuerDN(GetLicencerDN());
certificateGenerator.SetNotAfter(DateTime.Now.AddYears(100));
certificateGenerator.SetNotBefore(DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0)));
certificateGenerator.SetSignatureAlgorithm("SHA512withRSA");
certificateGenerator.SetPublicKey(keyPair.PublicKey);
var result = certificateGenerator.Generate(keyPair.PrivateKey);
this._clientCertificate = new X509Certificate2(DotNetUtilities.ToX509Certificate(result));
this._clientCertificate.PrivateKey = DotNetUtilities.ToRSA((RsaPrivateCrtKeyParameters)keyPair.PrivateKey);
Run Code Online (Sandbox Code Playgroud)
堆栈看起来像:
System.Security.Cryptography.CryptographicException: Bad Data.
Result StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey)
at …Run Code Online (Sandbox Code Playgroud) 我试图在 Dart 中创建一个 BigInt 只是为了了解 BigInt。
我试过这个
var x = 237462836487263478235472364782364827648632784628364;
Run Code Online (Sandbox Code Playgroud)
但这会产生错误,因为编译器认为它是一个 int 但大于 64 位。
然后我看到这个答案,所以我尝试了这个:
var x = BigInt.from(237462836487263478235472364782364827648632784628364);
Run Code Online (Sandbox Code Playgroud)
这仍然给出相同的错误:
整数文字 237462836487263478235472364782364827648632784628364 无法以 64 位表示。
如果您需要大于 9,223,372,036,854,775,807 或小于 -9,223,372,036,854,775,808 的整数,请尝试使用 BigInt 类。
我以为我正在使用 BigInt 类。
我有一个变量访问的X509Certificate ...
当我尝试获取证书的详细信息时,我设法通过提供的功能轻松获得CriticalExtensions值.
但是我想要达到的是无关键扩展,它存储在certifcate中并由Object ID#2.5.29.32表示
我想要访问的是政策标识号,如下图所示:http://i.stack.imgur.com/xo8zX.png
我使用了以下功能
cert.getExtensionValue("2.5.29.32");
Run Code Online (Sandbox Code Playgroud)
但它没有给我价值..任何人都可以告诉我我做错了什么?
PS:我正在使用java.security.cert.X509Certificate;
我看到了一个试图用Java解释继承的例子.Employee类是基类,它有三个实例变量和三个构造函数.它如下:
public class Employee{
private String name;
private int id;
public Employee(){
name = " No Name!";
id = 00100;
}
public Employee(String n, int i){
name = n;
id = i;
}
public Employee (Employee originalObject){
name = originalObject.name;
id = originalObject.id;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:第三个构造函数有什么意义?以及它如何接受Employee我们仍在处理的类的相同类型的参数?该计划已空的构造函数和另外一个,对于经过串name并int为id,为什么有一个额外的一个并不比前面两个构造得多?
我必须使用预共享密钥建立到远程服务器的TLS连接.我目前正在使用Bouncycastle的PSKTlsClient.我的初始化代码如下:
socket_ = new Socket(address,port);
tlsHandler_ = new TlsProtocolHandler(socket_.getInputStream(),socket_.getOutputStream());
pskTlsClient_ = new PSKTlsClient(tlsPskInfo_);
tlsHandler_.connect(pskTlsClient_);
Run Code Online (Sandbox Code Playgroud)
但是我得到这个堆栈跟踪:
java.io.IOException: Internal TLS error, this could be an attack
at org.bouncycastle.crypto.tls.TlsProtocolHandler.failWithError(Unknown Source)
at org.bouncycastle.crypto.tls.TlsProtocolHandler.safeReadData(Unknown Source)
at org.bouncycastle.crypto.tls.TlsProtocolHandler.connect(Unknown Source)
at common.network.Transport.PskTlsClientSocket.connect(PskTlsClientSocket.java:61)
Run Code Online (Sandbox Code Playgroud)
我还在消息中获得了TLS证书,其中传输了PSK,但我不知道如何建立这种连接.你有什么建议怎么办吗?
我正在使用 java.security.cert.X509Certificate 通过 SSL 套接字获取 SSL 证书。但是 X509Certificate 将证书的序列号作为 BigInteger 对象返回。我要的是冒号分隔值格式的序列号(类似于我们在浏览器中查看证书详情时看到的)。我们如何做到这一点?
我尝试了 toString(16),但我的序列号中仍然没有冒号。
请帮忙。
在此代码中,此行导致异常:
clearText = c.doFinal(Base64.decode(encryptedText, Base64.DEFAULT));
javax.crypto.BadPaddingException: pad block corrupted
我从以下代码获得了代码:http: //www.techrepublic.com/blog/software-engineer/attention-android-developers-keep-user-data-safe/
有任何想法吗?
private String decrypt (String encryptedText) {
byte[] clearText = null;
try {
SecretKeySpec ks = new SecretKeySpec(getKey(), "AES");
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.DECRYPT_MODE, ks);
clearText = c.doFinal(Base64.decode(encryptedText, Base64.DEFAULT));
return new String(clearText, "UTF-8");
} catch (Exception e) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
细节:我也在android上加密它
java ×5
bouncycastle ×3
encryption ×3
ssl ×3
aes ×2
cryptography ×2
.net ×1
android ×1
bigint ×1
bignum ×1
c ×1
c# ×1
constructor ×1
dart ×1
exception ×1
iis-7 ×1
inheritance ×1
integer ×1
java-me ×1
math ×1
open-source ×1
sockets ×1