Resize Bytes Array - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:AES

Description

Resize Bytes Array

Demo Code

/*//w w  w .j a  v  a 2 s .  c  o m
 * Copyright (c) 2007-2012, Masahiko Kamo (mkamo@mkamo.com).
 * All Rights Reserved.
 */
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{

        private static byte[] ResizeBytesArray(byte[] bytes, int newSize) {
            var ret = new byte[newSize];
            if (bytes.Length <= newSize) {
                for (int i = 0; i < bytes.Length; ++i) {
                    ret[i] = bytes[i];
                }
            } else {
                int pos = 0;
                for (int i = 0; i < bytes.Length; ++i) {
                    ret[pos] ^= bytes[i];
                    ++pos;
                    if (pos >= ret.Length) {
                        pos = 0;
                    }
                }
            }
            return ret;
        }
}

Related Tutorials