小编Har*_*hen的帖子

分别使用nodejs和c进行AES-128-cbc加密时,使用相同的密钥和IV但结果不同

我想使用AES-128-cbc加密/解密算法来加密/解密一些数据,并使用nodejs加密数据并使用c解密它们。但是发现使用相同的密钥和IV,两种语言的加密不同结果见下:

节点js代码:

var crypto = require('crypto');

var encrypt = function (key, iv, data) {
    var cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
    var crypted = cipher.update(data, 'utf8', 'binary');
    var cbase64  =   new Buffer(crypted, 'binary').toString('base64');
    //console.log(crypted);
    //console.log(cbase64);
    crypted += cipher.final('binary');
    //console.log("hahahaaaaaa:"+crypted.toString('hex'));
    crypted = new Buffer(crypted, 'binary').toString('base64');
    //var c16 = new Buffer(crypted, 'binary').toString(16);
    //console.log(crypted);
    //console.log(c16);

    return crypted;
};

var decrypt = function (key, iv, crypted) {
    crypted = new Buffer(crypted, 'base64').toString('binary');
    var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
    var decoded = decipher.update(crypted, 'binary', 'utf8');
    //console.log(decoded); …
Run Code Online (Sandbox Code Playgroud)

c encryption aes node.js

6
推荐指数
1
解决办法
8857
查看次数

调用JNI方法时如何获取Android上下文实例?

我已经在stackoverflow上阅读了一些相关答案,但似乎没有人回答我的问题。我将从本机代码中获取android ID,即在C代码中调用方法getAndroidIDfromNativeCode,(因此JVM通过方法在本机代码中初始化create_vm),大家知道在调用getContentResolver方法时,必须使用一个Android Context实例来调用,那么如何获取这个Context实例呢?

    static jstring
    native_code_getAndroidID(JNIEnv *env, jobject thiz)
    {
        jclass c_settings_secure = (*env)->FindClass(env, "android/provider/Settings$Secure");
        jclass c_context = (*env)->FindClass(env,"android/content/Context");
        if(c_settings_secure == NULL || c_context == NULL){
            return NULL;
        }
        //Get the getContentResolver method
        jmethodID m_get_content_resolver = (*env)->GetMethodID(env, c_context, "getContentResolver",
                                                               "()Landroid/content/ContentResolver;");
        if(m_get_content_resolver == NULL){
            return NULL;
        }
        //Get the Settings.Secure.ANDROID_ID constant
        jfieldID f_android_id = (*env)->GetStaticFieldID(env, c_settings_secure, "ANDROID_ID", "Ljava/lang/String;");

        if(f_android_id == NULL){
            return NULL;
        }
        jstring s_android_id = (*env)->GetStaticObjectField(env, c_settings_secure, f_android_id);

        //create a ContentResolver instance context.getContentResolver() …
Run Code Online (Sandbox Code Playgroud)

java java-native-interface android native-code

6
推荐指数
2
解决办法
1万
查看次数

如何从Unity3d相机捕获帧并将其实时显示在另一个rawImage上?

结果

我想从Unity3d虚拟相机中捕获帧,然后让它们显示在另一个原始图像上。结果是原始图像屏幕闪烁得非常厉害。

using UnityEngine;
using UnityEngine.UI;

public class RawImageVirtualWebCamTexture : MonoBehaviour
{
    private RawImage rawimage;

    void Start()
    {
        GameObject obj = GameObject.Find("RawImageTransform");
        rawimage = obj.GetComponent<RawImage>();
    }

    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (source != null)
        {
            rawimage.texture = source;
        }
        Graphics.Blit(source, destination);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想看到流畅的图片。但如何做到这一点呢?

camera unity-game-engine rawimage

2
推荐指数
1
解决办法
8866
查看次数

C#中如何解决类名冲突问题

我使用不使用命名空间的第三方 dll,它包含一个名为Speaker.

// Decompiled with JetBrains decompiler
// Type: Speaker
// Assembly: StreamSDK, Version=1.0.6782.19546, Culture=neutral,PublicKeyToken=null
// MVID: 82353EB3-505A-4A47-8EEB-ED74ED4FC9B9
// Assembly location: /Users/haha/test/Assets/_ThirdParty/SteamSDK/Core/XMLSerializer/StreamSDK.dll

public enum Speaker
{
  remote,
  local,
  none,
}
Run Code Online (Sandbox Code Playgroud)

我的本地项目在指定的命名空间下也有这个类名Photon.Voice.Unity;。导入 dll 后,发生错误,因为编译器将本地Speaker视为第三方的Speaker.

我已经在本地项目中使用了命名空间:

using Photon.Voice.Unity;
Run Code Online (Sandbox Code Playgroud)

错误发生在以下代码中:

private void OnSpeakerCreated(Speaker speaker)
{
    speaker.gameObject.transform.SetParent(this.RemoteVoicesPanel, false);
}
Run Code Online (Sandbox Code Playgroud)

错误:

error CS1061: 'Speaker' does not contain a definition for 'gameObject' and no accessible extension method 'gameObject' accepting a first argument of type 'Speaker' could be found …
Run Code Online (Sandbox Code Playgroud)

c# namespaces

0
推荐指数
1
解决办法
1780
查看次数