예제 #1
0
 private static byte[] F(byte[] salt, int iterationCount, int blockIndex, HMAC prf)
 {
     byte[] numArray  = prf.ComputeHash(Arrays.Concat(new byte[][] { salt, Arrays.IntToBytes(blockIndex) }));
     byte[] numArray1 = numArray;
     for (int i = 2; i <= iterationCount; i++)
     {
         numArray  = prf.ComputeHash(numArray);
         numArray1 = Arrays.Xor(numArray1, numArray);
     }
     return(numArray1);
 }
예제 #2
0
 private byte[] DeriveKey(IDictionary <string, object> header, int cekSizeBits, CngKey externalPublicKey, CngKey privateKey)
 {
     byte[] bytes     = Encoding.UTF8.GetBytes((string)header[this.algIdHeader]);
     byte[] numArray  = (header.ContainsKey("apv") ? Base64Url.Decode((string)header["apv"]) : Arrays.Empty);
     byte[] numArray1 = (header.ContainsKey("apu") ? Base64Url.Decode((string)header["apu"]) : Arrays.Empty);
     byte[] numArray2 = Arrays.Concat(new byte[][] { Arrays.IntToBytes((int)bytes.Length), bytes });
     byte[] numArray3 = Arrays.Concat(new byte[][] { Arrays.IntToBytes((int)numArray1.Length), numArray1 });
     byte[] numArray4 = Arrays.Concat(new byte[][] { Arrays.IntToBytes((int)numArray.Length), numArray });
     byte[] bytes1    = Arrays.IntToBytes(cekSizeBits);
     return(ConcatKDF.DeriveKey(externalPublicKey, privateKey, cekSizeBits, numArray2, numArray4, numArray3, bytes1));
 }
예제 #3
0
        private byte[] DeriveKey(IDictionary <string, object> header, int cekSizeBits, CngKey externalPublicKey, CngKey privateKey)
        {
            byte[] enc = Encoding.UTF8.GetBytes((string)header[algIdHeader]);
            byte[] apv = header.ContainsKey("apv") ? Base64Url.Decode((string)header["apv"]) : Arrays.Empty;
            byte[] apu = header.ContainsKey("apu") ? Base64Url.Decode((string)header["apu"]) : Arrays.Empty;

            byte[] algorithmId = Arrays.Concat(Arrays.IntToBytes(enc.Length), enc);
            byte[] partyUInfo  = Arrays.Concat(Arrays.IntToBytes(apu.Length), apu);
            byte[] partyVInfo  = Arrays.Concat(Arrays.IntToBytes(apv.Length), apv);
            byte[] suppPubInfo = Arrays.IntToBytes(cekSizeBits);

            return(ConcatKDF.DeriveKey(externalPublicKey, privateKey, cekSizeBits, algorithmId, partyVInfo, partyUInfo, suppPubInfo));
        }
예제 #4
0
파일: PBKDF2.cs 프로젝트: zzyzy/jose-jwt
        private static byte[] F(byte[] salt, int iterationCount, int blockIndex, HMAC prf)
        {
            byte[] U      = prf.ComputeHash(Arrays.Concat(salt, Arrays.IntToBytes(blockIndex))); // U_1 = PRF (P, S || INT (i))
            byte[] result = U;

            for (int i = 2; i <= iterationCount; i++)
            {
                U      = prf.ComputeHash(U);                                                // U_c = PRF (P, U_{c-1}) .
                result = Arrays.Xor(result, U);                                             // U_1 \xor U_2 \xor ... \xor U_c
            }

            return(result);
        }