小编jas*_*604的帖子

为什么 HMAC sha256 在 PHP 和 Javascript 上返回不同的值

我正在尝试使用 CryptoJS 在 Javascript 中构建一个 HMAC SHA256 字符串,我现有的代码是使用 Akamai 库用 PHP 编写的。

在某些情况下,与 PHP 相比,我得到了不同的结果,我无法理解为什么它会给我不同的结果

    /* 
       <php> Using native hash_hmac
       Generating key by concatenating char 
    */ 

      $signature1 = hash_hmac('SHA256', "st=1453362060~exp=1453363260~acl=/*", chr(63));
      $signature2 = hash_hmac('SHA256', "st=1453362060~exp=1453363260~acl=/*", chr(63) . chr(23));
      $signature3 = hash_hmac('SHA256', "st=1453362060~exp=1453363260~acl=/*", chr(63) . chr(23) . chr(253));

    /*
       here is result from php
       signature1 : 3e086bb48ab9aafa85661f9ce1b7dac49befddf117ce2a42d93c92b6abe513ce ( matched: same as JavaScript)
       signature2 : 3667dd414a50f68f7ce083e540f27f68f7d0f18617b1fb1e4788bffeaeab59f6( matched: same as JavaScript)
       signature3 : dd5a20041661046fdee871c8b9e77b3190fbbf85937c098090a1d524719b6aa9 ( not matched: diff from JavaScript)
    */


    /* 
       <JavaScript> …
Run Code Online (Sandbox Code Playgroud)

javascript php sha256 hmac cryptojs

7
推荐指数
1
解决办法
3757
查看次数

PHP5.6是CLASS常量中允许的数组

所以我们可以在PHP5.6中定义数组常量.但是,在类中定义数组常量时出现以下错误

Arrays are not allowed in class constants
Run Code Online (Sandbox Code Playgroud)

那么数组常量是允许的,但不是在类内部吗?

php arrays class constants php-5.6

7
推荐指数
1
解决办法
7588
查看次数

使用JQuery使用JWT,不断收到错误

我目前正在使用JSONWebtoken与NodeJS构建API.当我尝试使用标头中的令牌时,我收到错误403,它直接转到下面代码中的else语句,这意味着令牌根本就不存在.

以下是我在服务器端获取令牌的方法:

router.use(function(req, res, next){

var token = req.body.token || req.query.token || req.headers['x-access-token'];

  //decode token
  if(token)   {
    jwt.verify(token, app.get('secretKey'), function(err, decoded){
      if(err)
        return res.json({ success:false, message: 'failed, token problem'});
      else {
        req.decoded = decoded;
        next();
      }
    });
  }else {
    return res.status(403).send({
      success:false,
      message: 'token not provided'
    })
  }
});
Run Code Online (Sandbox Code Playgroud)

在客户端,我正在使用JQuery并将其保存在cookie中:

  1. 令牌作为数据工作:

    $.ajax({
      type:'GET',
      dataType: 'jsonp',
      url :"http://localhost:3000/api/users",
      data : {
        token : $.cookie('token')
      },
      success: function(data, status) {
        console.log("Status " + status);
        console.log(data);
      }
    });
    
    Run Code Online (Sandbox Code Playgroud)
  2. 令牌作为参数也有效

    $.get("http://localhost:3000/api/users?token=" + $.cookie('token'))
     .done(function(data){ …
    Run Code Online (Sandbox Code Playgroud)

jquery node.js jwt

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

使用golang分离整数和小数部分

我是 Golang 新手。我想将浮点数分为整数部分和小数部分。经过一番研究后,我实现了它,但我的代码存在问题。我使用 5.8 作为输入,但结果是 5 和 0.79999。

package main

import(
        "fmt"
        "math"
)    

func Round2(val float64) {
        intpart, div := math.Modf(val)
        fmt.Println(div)

        fmt.Println(intpart)

}

func main() {
        fmt.Println("Hello, playground")
        Round2(5.8)
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个,我得到的输出是:

0.7999999999999998
5
Run Code Online (Sandbox Code Playgroud)

如果有任何其他方法可以做到这一点,请告诉我。我已经插入了包含我的代码的 go Playground。

https://play.golang.org/p/O4n0k0XyMX

go

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

Visual Studio Xamarin项目的推荐.gitignore文件

环顾四周,我似乎无法找到Visual Studio Xamarin项目的推荐模板.gitignore文件.我也在这里看了https://github.com/github/gitignore

Visual Studio一个可以吗?

https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

Thx提前.

gitignore visual-studio xamarin

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

Spring JWT - 添加自定义声明

你能帮我解决我的问题吗?我使用 Spring OAuth2 为我的客户端生成了 JWT。我已经实现了一个授权和资源服务器以及一些网络安全配置,一切都通过在线指南完成。

它工作正常,但现在我想编辑有效负载并添加自定义属性,例如用户的名字和姓氏等。你能检查我的代码并告诉我我应该怎么做才能将其他属性添加到有效负载中吗?谢谢。

这是我的实现:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Value("${security.signing-key}")
    private String signingKey;

    @Value("${security.encoding-strength}")
    private Integer encodingStrength;

    @Value("${security.security-realm}")
    private String securityRealm;

    @Autowired
    private UserDetailsService userDetailsService;

    @Bean
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService)
                .passwordEncoder(new BCryptPasswordEncoder());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .httpBasic()
                .realmName(securityRealm)
                .and()
                .csrf()
                .disable();

    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter converter = …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security jwt spring-security-oauth2

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

了解OuterIterator接口PHP

我正在尝试OuterIterator在类上实现接口,但不确定在该方法中使用什么getInnerIterator。我知道它应该返回一个Iterator,但是我不明白在什么情况下应该返回一个Iterator,InnerIterator尽管它已经具有Iterator接口的所有方法,那么为什么需要一个InnerIterator

我完全迷失了 OuterIterator

class myouterIterator implements OuterIterator 
{
    /**
    * Returns the inner Iterator for the current entry
    */
    public $data = array(1,2,3,4,5,6,7,8,9,10);
    public $position = 0;
    public function getInnerIterator()
    {
        // What code should be place here
    }
    public function rewind()
    {
        $this->position = 0;
    }
    public function valid()
    {
        return isset($this->data[$this->position]);
    }
    public function key()
    {
        return $this->position;
    }
    public function current()
    {
        return $this->data[$this->position];
    }
    public function next()
    { …
Run Code Online (Sandbox Code Playgroud)

php spl iterator

5
推荐指数
1
解决办法
884
查看次数

如何在共享主机上安装Redis?

我正在开发一个 Laravel 项目,并使用 Predis 来缓存数据库查询。现在我必须在我的服务器上安装 Redis。是否可以在共享主机上安装 Redis?

php redis laravel predis

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

在哪里与looper"退出"?

我有一个弯针的问题.我打电话looper.prepare(),做完之后一切正常.但如果我旋转设备,我会在准备工作中遇到异常.

07-12 16:40:09.760: E/activity(15809):  java.lang.RuntimeException: Only one Looper may be created per thread
Run Code Online (Sandbox Code Playgroud)

我正试图退出弯针,但它没有做任何事情.

这是我的AsyncTask:

 @Override
    protected String doInBackground(String... args) {

        try{Looper.prepare();   //here start the exception

       try {  

            URL  url = new URL(link); 
            HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
         conn.setDoInput(true);   
            conn.connect();  
            InputStream is = conn.getInputStream();
          utente.measure(0, 0);
            bmImg = decodeSampledBitmapFromResource(is,(int) utente.getMeasuredWidth(), utente.getMeasuredHeight(), link);

 if(bmImg!=null){


        try{  

         getCroppedBitmap();
        }catch(Exception e){
            System.out.println(e);
        }

          }

        }
        catch (IOException e)
        {       
           Log.e("lele", "errore qui");
            e.printStackTrace();  

        }
        Looper.myLooper().quit();   //do nothings
        }catch(Exception e){
            Log.e("canta tu",  " …
Run Code Online (Sandbox Code Playgroud)

android exit looper android-asynctask

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

使用PHP进行JSON解析获取信息

我正在尝试使用PHP从JSON数据结构中解析一些信息.我的foreach工作真的很奇怪:

[query] => Array (
 [count] => 2
 [created] => 2014-05-12
 [lang] => de-DE
 [results] => Array (
     [rate] => Array (
         [0] => Array (
             [id] => 1
             [Name] => User1
             [Rate] => 64.5245
             [Date] => 8/13/2013
             )
         [1] => Array (
             [id] => 2
             [Name] => User2
             [Rate] => 71.9697
             [Date] => 8/3/2014
             )
         )
     )
 )
Run Code Online (Sandbox Code Playgroud)

我需要解析Name,Ratecreated(从数组开头的日期).

我的代码是:

foreach ($json_var['query']['results']['rate'][0] as $key=>$value) {
    echo $value['Name'];
}
Run Code Online (Sandbox Code Playgroud)

但是我遇到了很多错误.如果我在没有[0]的情况下尝试,我会得到两个用户的名字.

你能帮我吗?非常感谢你!

php arrays foreach json

3
推荐指数
1
解决办法
61
查看次数