我正在寻找CommonCrypto中基于ECDH(椭圆曲线Diffie-Hellman)生成共享密钥的方法。我可以找到像这样的专有实现https://github.com/surespot/surespot-ios/blob/master/surespot/encryption/EncryptionController.mm,但是这不是使用CommonCrypto。计算共享密钥的方法有时称为密钥交换,其中包括共享密钥的计算。有人可以发送链接到正确的文档,也可以发送示例到使用CommonCrypto生成基于椭圆曲线Diffie-Hellman的共享密钥的示例吗?
我得到一个 64 位未压缩的公钥,需要运行 ECDH 来生成一个共享密钥。为了调用 ECDH,我需要将字节数组转换为,PublicKey并且我正在使用我在本论坛中找到的以下代码:
public static void setOtherPublicKey(byte[] publicKeyBytes) throws NoSuchAlgorithmException, InvalidKeySpecException
{
try {
//EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedPrivateKey);
KeyFactory generator = KeyFactory.getInstance("EC");
//PrivateKey privateKey = generator.generatePrivate(privateKeySpec);
EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyBytes);
blePubKey = generator.generatePublic(publicKeySpec);
} catch (Exception e) {
throw new IllegalArgumentException("Failed to create KeyPair from provided encoded keys", e);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码抛出一个InvalidKeySpecException.
例如,对方的公钥是:
public static void setOtherPublicKey(byte[] publicKeyBytes) throws NoSuchAlgorithmException, InvalidKeySpecException
{
try {
//EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedPrivateKey);
KeyFactory generator …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码为示例程序设置动画:
AnimationDrawable animation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
ImageView animatedImage = (ImageView) findViewById(R.id.animation);
animatedImage.setBackgroundResource(R.drawable.animate_bag);
animation = (AnimationDrawable) animatedImage.getBackground();
}
public void startAnimate(View v)
{
if (animation != null)
animation.start();
} //eof OnClick
Run Code Online (Sandbox Code Playgroud)
XML 文件是:
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate"
android:onClick="startAnimate" />
<ImageView
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/animate_bag" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是 animationImage.getBackground() 返回 null。
会欣赏你的提示:-)
谢谢,西蒙
我正在使用 ECDH 在 Alice 和 Bob 之间共享一个秘密,一个在 Android 上运行,另一个在嵌入式上运行。我的理解是,最佳实践是双方生成 AES 密钥来加密消息。有人可以发送一些示例,说明 Alice 和 Bob 在使用 ECDH 就共享密钥达成一致后如何生成相同的 AES 密钥吗?
我有一个简单的Android应用程序,它使用我构建的JAR.在尝试生成最终存档时,我收到上述错误.导出JAR时我排除了AndroidManifest.xml.我尝试清理项目并从JAR中删除ic_launcher.png但是在尝试构建JAR时我收到了一个错误.有任何想法吗?
只要我有一个调试密钥,我就可以看到地图(mapview).今天我在Goolge的网站上获得了一个发布密钥(在生成证书fingetprint之后).一旦我用我获得的新版本密钥替换调试密钥,就不再显示地图了.在看到地图之前,还有其他步骤吗?
谢谢.
android ×5
cryptography ×2
aes ×1
apk ×1
bouncycastle ×1
debugging ×1
duplicates ×1
encryption ×1
ios ×1
jar ×1
null ×1
release ×1