OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library crypto.crypto_utils; | |
6 | |
7 import 'base64.dart'; | 5 import 'base64.dart'; |
8 | 6 |
9 /// Utility methods for working with message digests. | 7 /// Utility methods for working with message digests. |
10 abstract class CryptoUtils { | 8 abstract class CryptoUtils { |
11 /// Convert a list of bytes (for example a message digest) into a hexadecimal | 9 /// Convert a list of bytes (for example a message digest) into a hexadecimal |
12 /// string. | 10 /// string. |
13 static String bytesToHex(List<int> bytes) { | 11 static String bytesToHex(List<int> bytes) { |
14 var result = new StringBuffer(); | 12 var result = new StringBuffer(); |
15 for (var part in bytes) { | 13 for (var part in bytes) { |
16 result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); | 14 result.write('${part < 16 ? '0' : ''}${part.toRadixString(16)}'); |
(...skipping 21 matching lines...) Expand all Loading... |
38 /// Converts a [Base64-encoded][rfc] String into list of bytes. | 36 /// Converts a [Base64-encoded][rfc] String into list of bytes. |
39 /// | 37 /// |
40 /// [rfc]: https://tools.ietf.org/html/rfc4648 | 38 /// [rfc]: https://tools.ietf.org/html/rfc4648 |
41 /// | 39 /// |
42 /// This ignores "\r\n" sequences in [input]. It accepts both URL-safe and | 40 /// This ignores "\r\n" sequences in [input]. It accepts both URL-safe and |
43 /// -unsafe Base 64 encoded strings. | 41 /// -unsafe Base 64 encoded strings. |
44 /// | 42 /// |
45 /// Throws a [FormatException] if [input] contains invalid characters. | 43 /// Throws a [FormatException] if [input] contains invalid characters. |
46 static List<int> base64StringToBytes(String input) => BASE64.decode(input); | 44 static List<int> base64StringToBytes(String input) => BASE64.decode(input); |
47 } | 45 } |
OLD | NEW |